
TCS NQT Exam 1-Shift Coding Question | TCS NQT Exam 20/03/2026 Coding Question | TCS Exam Question
TCS NQT Exam 1-Shift Coding Question | TCS NQT Exam 20/03/2026 Coding Question
Q1. Gym Membership Cost – Problem Statement
A gym offers membership plans based on the number of months a customer wants to enroll. The cost of the membership is determined as follows:
| Duration (Months) | Cost (₹) |
|---|---|
| ≤ 0 | Invalid Input |
| 1 | 2000 |
| 2 to 3 | 5000 |
| 4 to 6 | 9000 |
| > 6 | 15000 |
Task
Write a program that:
- Takes an integer input for months
- Prints:
"Invalid Input"ifmonths <= 0- Otherwise prints:
Cost: <amount>
Input Format
- A single integer
months
Output Format
- Print
"Invalid Input"OR - Print:
Cost: <amount>
Sample Test Cases
Test Case 1
Input:
1
Output:
Cost: 2000
Test Case 2
Input:
3
Output:
Cost: 5000
Test Case 3
Input:
5
Output:
Cost: 9000
Test Case 4
Input:
7
Output:
Cost: 15000
Test Case 5
Input:
0
Output:
Invalid Input
Solutions
🔹 C++ Solution
#include <iostream>
using namespace std;
int main() {
int months;
cin >> months;
if(months <= 0) {
cout << "Invalid Input";
}
else if(months == 1) {
cout << "Cost: 2000";
}
else if(months <= 3) {
cout << "Cost: 5000";
}
else if(months <= 6) {
cout << "Cost: 9000";
}
else {
cout << "Cost: 15000";
}
return 0;
}
🔹 Java Solution
import java.util.*;
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 == 1){
System.out.println("Cost: 2000");
}
else if(months <= 3){
System.out.println("Cost: 5000");
}
else if(months <= 6){
System.out.println("Cost: 9000");
}
else{
System.out.println("Cost: 15000");
}
}
}
🔹 Python Solution
months = int(input())
if months <= 0:
print("Invalid Input")
elif months == 1:
print("Cost: 2000")
elif months <= 3:
print("Cost: 5000")
elif months <= 6:
print("Cost: 9000")
else:
print("Cost: 15000")
TCS NQT Exam 1-Shift Coding Question
Q2. Transaction Monitoring System – Problem Statement
You are building a Transaction Monitoring System for a financial platform. The system processes N transactions. Each transaction contains the following 4 parameters:
- Sender (string)
- Receiver (string)
- Timestamp (integer, in seconds)
- Amount (integer)
Rules
1. Duplicate Transaction Check
If any transaction has the same sender AND receiver as a previous transaction, print:
Error: Duplicate Transaction. Terminate the program.
2. Fraud Detection Rule
If the difference between the timestamps of any two consecutive transactions is greater than 60 seconds, print:
Fraud Detected and terminate the program.
3. Valid Case
If all transactions are valid, print: All Transactions Valid
Input Format
- First line: Integer N (number of transactions)
- Next N lines:
- Each line contains:
sender receiver timestamp amount
Output Format
Print one of the following:
- “Error: Duplicate Transaction”
- “Fraud Detected”
- “All Transactions Valid”
Constraints
- 1 ≤ N ≤ 10^5
- timestamp ≥ 0
- amount ≥ 0
Sample Test Case
Test Case 1 (Valid Transactions)
Input
3
A B 10 100
C D 50 200
E F 200 300
Output
All Transactions Valid
Test Case 2 (Duplicate Sender-Receiver)
Input:
3
A B 10 100
C D 50 200
E F 200 300
Output
Error: Duplicate Transaction
Test Case 3 (Fraud Detection)
Input:
3
A B 10 100
C D 50 200
E F 200 300
Output
Fraud Detected
Solutions
🔹 C++ Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
set<pair<string,string>> seen;
int prevTime = -1;
for(int i = 0; i < N; i++) {
string sender, receiver;
int timestamp, amount;
cin >> sender >> receiver >> timestamp >> amount;
if(seen.count({sender, receiver})) {
cout << "Error: Duplicate Transaction";
return 0;
}
seen.insert({sender, receiver});
if(prevTime != -1 && (timestamp - prevTime > 60)) {
cout << "Fraud Detected";
return 0;
}
prevTime = timestamp;
}
cout << "All Transactions Valid";
}
🔹 Java Solution
import java.util.*;
public class TransactionSystem {
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();
int amount = sc.nextInt();
String key = sender + "-" + receiver;
if(seen.contains(key)) {
System.out.println("Error: Duplicate Transaction");
return;
}
seen.add(key);
if(prevTime != -1 && (timestamp - prevTime > 60)) {
System.out.println("Fraud Detected");
return;
}
prevTime = timestamp;
}
System.out.println("All Transactions Valid");
}
}
🔹 Python Solution
n = int(input())
seen = set()
prev_time = -1
for _ in range(n):
sender, receiver, timestamp, amount = input().split()
timestamp = int(timestamp)
key = (sender, receiver)
if key in seen:
print("Error: Duplicate Transaction")
exit()
seen.add(key)
if prev_time != -1 and (timestamp - prev_time > 60):
print("Fraud Detected")
exit()
prev_time = timestamp
print("All Transactions Valid")
Join our Telegram group: Click Here
Follow us on Instagram: Click Here
Join our WhatsApp group: Click Here
More Latest Off-Campus Hiring 2025 Jobs:
- Accenture New Mass Hiring 2025 – Click Here
- Naukri Campus Hiring Drive Registration –Click Here