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 classGymMembership {
public static voidmain(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");
}
}
import java.util.*;
public classTransactionMonitor {
public static voidmain(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 = -1for _ inrange(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 != -1and (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 classDiscount {
public static voidmain(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.05if a < 1000else0.10if a < 5000else0.15print(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
defsolve(arr, pos, N, R, END):
if pos == N:
return1if arr[-1] == END else0
total = 0for s inrange(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] = 1print(solve(arr, 1, N, R, END))
5
Parking Fee Calculation Easy
Calculate parking fee by tiered rate. Handle non-integer input with “ERROR”.
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 = 0for w in weights:
if total + w <= cap:
total += w
count += 1else:
breakprint(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 = 0for r inrange(1, n+1):
for combo incombinations(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
Sort all edges by weight (ascending)
For each edge, add it if it doesn’t form a cycle (use Union-Find)
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 classMST {
static int[] parent, rank;
static intfind(int x) {
if (parent[x] != x) parent[x] = find(parent[x]);
return parent[x];
}
static booleanunion(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 voidmain(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
deffind(p, x):
if p[x] != x: p[x] = find(p, p[x])
return p[x]
defunion(p, r, a, b):
pa, pb = find(p,a), find(p,b)
if pa==pb: return Falseif r[pa]<r[pb]: pa,pb=pb,pa
p[pb]=pa
if r[pa]==r[pb]: r[pa]+=1return True
V,E = map(int,input().split())
edges = [tuple(map(int,input().split())) for _ inrange(E)]
edges.sort(key=lambda x: x[2])
parent=[*range(V+1)]; rank=[0]*(V+1)
cost=used=0for u,v,w in edges:
ifunion(parent,rank,u,v):
cost+=w; used+=1if used==V-1: breakprint(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
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.
0 Comments
if you have any doubt, plz let me know