Ad Code

NEW POST

6/recent/ticker-posts

TCS NQT March 2026 Coding Questions with Java & Python Solutions

https://ift.tt/dw0RKNA

🔥 March 2026 — Actual Exam

TCS NQT March 2026 Coding Questions
with Java & Python Solutions

8 real questions from TCS NQT Shift 1 & 2 (March 20–21, 2026) — fully solved, explained, and ready for your next attempt.

📅 March 20–21, 2026
💻 Java + Python
✅ All Test Cases Covered
⏱ 70 min Coding Round

Home
TCS NQT March 2026 Coding Questions

If you’re preparing for TCS NQT 2026, stop scrolling through random LeetCode problems.
This page contains the actual coding questions that appeared in TCS NQT on March 20 and March 21, 2026 — compiled from student reports immediately after the exam. Every solution is tested and passes all given test cases in both Java and Python.

8
Real Questions
2
Languages (Java + Python)
100%
Test Cases Passing

TCS NQT 2026 Exam Structure — What You Need to Know

Before diving into questions, understand the exam format. Many students waste time on the wrong sections. Here’s the confirmed breakdown for the March 2026 exam:

Section Questions Time Part
Numerical Ability 20 25 min Foundation (Part A)
Verbal Ability 25 25 min Foundation (Part A)
Reasoning Ability 20 25 min Foundation (Part A)
Advanced Quantitative & Reasoning 15 Advanced (Part B)
Coding (2 problems) 2 70 min Advanced (Part B)

💡 Pro Tip: The Advanced section (Part B) is mandatory if you’re targeting Digital or Prime cadre (₹7–12 LPA). Most students skip it — that’s your competitive advantage.

Questions asked in TCS NQT March 2026 -Check out

1

Gym Membership Cost
Easy

A gym offers membership plans based on the number of months a customer enrolls. Write a program that prints the total membership cost or an appropriate message for edge cases.

📐 Pricing Rules

Duration Cost (₹)
1 month ₹2,000
2 or 3 months ₹5,000
4 to 6 months ₹9,000
9 months ₹12,000
12 months ₹15,000
Input < 0 invalid input
Input = 0 0
Any other value Error

🧪 Test Cases

Input
3
Output
5000
Input
-1
Output
invalid input

☕ Java Solution

☕ Java
import java.util.Scanner;

public class GymMembership {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int months = sc.nextInt();

        if (months < 0)         System.out.println("invalid input");
        else if (months == 0)   System.out.println(0);
        else if (months == 1)   System.out.println(2000);
        else if (months <= 3)  System.out.println(5000);
        else if (months <= 6)  System.out.println(9000);
        else if (months == 9)  System.out.println(12000);
        else if (months == 12) System.out.println(15000);
        else                    System.out.println("Error");
    }
}

🐍 Python Solution

🐍 Python 3
months = int(input())

if   months < 0:    print("invalid input")
elif months == 0:   print(0)
elif months == 1:   print(2000)
elif months <= 3:   print(5000)
elif months <= 6:   print(9000)
elif months == 9:   print(12000)
elif months == 12:  print(15000)
else:               print("Error")
💡 Key Insight: Classic if-else ladder. Watch the edge cases — months=0 returns 0, negative returns “invalid input”. Both are different outputs!

2

Transaction Monitoring System
Medium

Given N transactions (Sender, Receiver, Timestamp, Amount), validate them against fraud and duplication rules.

📐 Rules

  • Same Sender + Receiver seen before → error duplication transaction
  • Consecutive timestamp difference > 60 seconds → fraud detected
  • All valid → all transaction are valid

🧪 Test Cases

Input
2
A B 100 500
A B 110 600
Output
error duplication transaction
Input
2
A B 100 500
C D 200 300
Output
fraud detected

☕ Java Solution

☕ Java
import java.util.*;

public class TransactionMonitor {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> seen = new HashSet<>();
        int prevTime = -1;

        for (int i = 0; i < n; i++) {
            String sender   = sc.next();
            String receiver = sc.next();
            int timestamp  = sc.nextInt();
            sc.nextInt(); // amount — not used

            String key = sender + "-" + receiver;
            if (seen.contains(key)) {
                System.out.println("error duplication transaction");
                return;
            }
            seen.add(key);

            if (prevTime != -1 && (timestamp - prevTime) > 60) {
                System.out.println("fraud detected");
                return;
            }
            prevTime = timestamp;
        }
        System.out.println("all transaction are valid");
    }
}

🐍 Python Solution

🐍 Python 3
n = int(input())
seen = set()
prev_time = -1

for _ in range(n):
    s, r, t, a = input().split()
    t = int(t)
    key = s + '-' + r

    if key in seen:
        print("error duplication transaction")
        exit()
    seen.add(key)

    if prev_time != -1 and (t - prev_time) > 60:
        print("fraud detected")
        exit()
    prev_time = t

print("all transaction are valid")
💡 Key Insight: Always check duplicate first, then fraud. HashSet lookup is O(1). String key = sender+”-“+receiver uniquely identifies a pair.

3

Purchase Discount Calculator
Easy

Given a purchase amount, apply a tiered discount and print the final amount rounded to 2 decimal places.

Amount Range Discount
Amount < 1000 5%
1000 ≤ Amount < 5000 10%
Amount ≥ 5000 15%
Input → Output
800  → 760.00
3000 → 2700.00
6000 → 5100.00
Formula
final = amount - (amount × discount)
rounded to 2 decimals

☕ Java Solution

☕ Java
import java.util.Scanner;
public class Discount {
    public static void main(String[] args) {
        double amt = new Scanner(System.in).nextDouble();
        double d = amt < 1000 ? 0.05 : amt < 5000 ? 0.10 : 0.15;
        System.out.printf("%.2f%n", amt - amt * d);
    }
}

🐍 Python Solution

🐍 Python 3
a = float(input())
d = 0.05 if a < 1000 else 0.10 if a < 5000 else 0.15
print(f"{a - a*d:.2f}")

4

Arrange the King’s Army
Medium

Count valid sequences of length N using soldiers 1 to R where: first = 1, last = END, no two adjacent soldiers are equal.

Input
N=3, R=3, END=2
Output
1  →  [1,3,2]

🐍 Python Solution

🐍 Python 3
def solve(arr, pos, N, R, END):
    if pos == N:
        return 1 if arr[-1] == END else 0
    total = 0
    for s in range(1, R+1):
        if s != arr[pos-1]:
            arr[pos] = s
            total += solve(arr, pos+1, N, R, END)
    return total

N, R, END = int(input()), int(input()), int(input())
arr = [0]*N
arr[0] = 1
print(solve(arr, 1, N, R, END))

5

Parking Fee Calculation
Easy

Calculate parking fee by tiered rate. Handle non-integer input with “ERROR”.

Hours Rate
First 2 hours ₹100/hr → total ₹200 max
Next 3 hours (hrs 3–5) ₹50/hr → adds ₹150 max
Beyond 5 hours ₹20/hr
Non-integer input ERROR
Input → Output
2   → 200
6   → 370
SIX → ERROR
Breakdown for 6
2×100 = 200
3×50  = 150
1×20  =  20
─────────
Total = 370

🐍 Python Solution

🐍 Python 3
try:
    h = int(input())
    fee = (min(h, 2) * 100 +
           max(0, min(h, 5) - 2) * 50 +
           max(0, h - 5) * 20)
    print(fee)
except ValueError:
    print("ERROR")

6

Balloon Capacity — Greedy
Easy

Given weights of people and max balloon capacity, find the maximum number of people that can fit. Always pick the lightest person first.

Input
weights=[20,30,40,50]
maxWeight=100
Output
3  (20+30+40=90 ≤ 100)

🐍 Python Solution

🐍 Python 3
n = int(input())
weights = list(map(int, input().split()))
cap = int(input())

weights.sort()  # greedy: smallest first
count = total = 0
for w in weights:
    if total + w <= cap:
        total += w
        count += 1
    else:
        break
print(count)
💡 Why Greedy Works: Sorting ensures we maximize the count of people by always adding the minimum weight possible, leaving room for more.

7

Maximum Subset Sum ≤ K
Medium

Find the maximum possible sum from any subset of the array such that the sum does not exceed K.

Input
ARR=[2,3,5,7], K=10
Output
10  (2+3+5=10)

🐍 Python Solution

🐍 Python 3
from itertools import combinations

n = int(input())
arr = list(map(int, input().split()))
k = int(input())

best = 0
for r in range(1, n+1):
    for combo in combinations(arr, r):
        s = sum(combo)
        if s <= k:
            best = max(best, s)
print(best)

8

Minimum Cost to Connect All Nodes (MST)
Hard ⚠

Given a graph with V vertices and E edges (each with a weight), find the Minimum Spanning Tree (MST) cost using Kruskal’s Algorithm.

📐 Algorithm: Kruskal’s + Union-Find

  1. Sort all edges by weight (ascending)
  2. For each edge, add it if it doesn’t form a cycle (use Union-Find)
  3. Stop when V-1 edges are added
Input
4 5
1 2 10
1 3 6
1 4 5
2 4 15
3 4 4
Output
Minimum Cost: 19
(edges: 3-4=4, 1-4=5, 1-2=10)

☕ Java Solution

☕ Java — Kruskal’s Algorithm
import java.util.*;
public class MST {
    static int[] parent, rank;
    static int find(int x) {
        if (parent[x] != x) parent[x] = find(parent[x]);
        return parent[x];
    }
    static boolean union(int a, int b) {
        int pa = find(a), pb = find(b);
        if (pa == pb) return false;
        if (rank[pa] < rank[pb]) { int t=pa; pa=pb; pb=t; }
        parent[pb] = pa;
        if (rank[pa] == rank[pb]) rank[pa]++;
        return true;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int V = sc.nextInt(), E = sc.nextInt();
        int[][] edges = new int[E][3];
        for (int i=0; i<E; i++) {
            edges[i][0]=sc.nextInt(); edges[i][1]=sc.nextInt(); edges[i][2]=sc.nextInt();
        }
        Arrays.sort(edges, (a,b) -> a[2]-b[2]);
        parent = new int[V+1]; rank = new int[V+1];
        for (int i=0; i<=V; i++) parent[i]=i;
        int cost=0, used=0;
        for (int[] e : edges) {
            if (union(e[0],e[1])) { cost+=e[2]; if (++used==V-1) break; }
        }
        System.out.println("Minimum Cost: " + cost);
    }
}

🐍 Python Solution

🐍 Python 3 — Kruskal’s Algorithm
def find(p, x):
    if p[x] != x: p[x] = find(p, p[x])
    return p[x]

def union(p, r, a, b):
    pa, pb = find(p,a), find(p,b)
    if pa==pb: return False
    if r[pa]<r[pb]: pa,pb=pb,pa
    p[pb]=pa
    if r[pa]==r[pb]: r[pa]+=1
    return True

V,E = map(int,input().split())
edges = [tuple(map(int,input().split())) for _ in range(E)]
edges.sort(key=lambda x: x[2])
parent=[*range(V+1)]; rank=[0]*(V+1)
cost=used=0
for u,v,w in edges:
    if union(parent,rank,u,v):
        cost+=w; used+=1
        if used==V-1: break
print(f"Minimum Cost: {cost}")
💡 Key Insight: Kruskal’s is greedy over edges. Union-Find (DSU) detects cycles in O(α(n)) ≈ O(1). Time complexity: O(E log E).

How to Crack TCS NQT 2026 — Strategy

  • Week 1: Master conditionals, loops, arrays — 80% of Easy questions come from here
  • Week 2: HashMap, HashSet, String manipulation — Medium question territory
  • Week 3: Recursion, backtracking, greedy — covers Medium-Hard
  • Week 4: Graphs (BFS, DFS, MST), DP basics — Advanced round preparation
🎯 Output Format is Critical: TCS uses exact string matching. “Error” ≠ “error” ≠ “ERROR”. Match the output format shown in the problem — character for character.

Frequently Asked Questions

What coding questions were asked in TCS NQT March 2026? +
TCS NQT March 2026 included: Gym Membership Cost, Transaction Monitoring, Purchase Discount Calculator, King’s Army Sequences, Parking Fee, Balloon Capacity (Greedy), Maximum Subset Sum ≤ K, and Minimum Cost to Connect All Nodes (Kruskal’s).
How many coding questions are in TCS NQT? +
The Foundation section has 2 coding questions in 70 minutes. The Advanced section has 1-2 harder problems. Total coding time is approximately 90 minutes.
Java or Python — which should I use? +
Both are accepted. Python is faster to write for medium problems. Java is preferred for strong OOP structure. Python is recommended for speed during the exam.
What is the TCS NQT 2026 cutoff for Digital/Prime? +
TCS doesn’t officially publish cutoffs. Based on student reports, scoring above 70% in Foundation + completing at least one coding problem fully is sufficient for Ninja. For Digital/Prime, aim to solve the hard coding problem.

PD
PlacementDrive Team
Placement Coaching & Tech Interview Preparation
We’ve been tracking TCS NQT patterns since 2020 and have helped 10,000+ students crack placements at TCS, Infosys, Wipro, and Cognizant. Follow us on Instagram @Placementdrive for daily prep content.

Keep Preparing — Related Posts

Useful Links:

The post TCS NQT March 2026 Coding Questions with Java & Python Solutions appeared first on placementdriveinsta.in.

Post a Comment

0 Comments