TCS NQT 2025 Coding Questions with Solutions

 

TCS NQT 2025 Coding Questions with Solutions

TCS NQT 2025 Coding Questions with Solutions 
Are you gearing up for the TCS NQT 2025 exam? Whether you're a beginner or an experienced candidate, practicing these essential coding problems will enhance your preparation. We've compiled some of the top coding questions from TCS NQT 2025 along with detailed solutions. These questions cover key areas such as arrays, dynamic programming, and bit manipulation, ensuring you're ready for the coding section. Start preparing now and sharpen your problem-solving skills with these TCS NQT 2025 coding questions!

1. Sum of Integers in a Range

Problem Statement:

Given a range [m, n] where 0 <= m, n <= 10000, find the sum of all integers between m and n (both inclusive).

Example:

Input:
0 3
Output:
6

Explanation:
0 + 1 + 2 + 3 = 6

Solution (Java):

java

import java.util.Scanner; public class SumInRange { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int m = scanner.nextInt(); int n = scanner.nextInt(); scanner.close(); int sum = 0; for (int i = m; i <= n; i++) { sum += i; } System.out.println(sum); } }

Solution (Python):

python

# Read input m, n = map(int, input().split()) # Calculate the sum result = sum(range(m, n + 1)) # Print the result print(result)

2. Minimum Team Selection to Cover Required Skills

Problem Statement:

Given a list of required skills and a list of candidates, each candidate has a subset of skills. Your goal is to select the smallest possible team such that all required skills are covered.

You are given:

  1. A list of required skills.
  2. The number of candidates (N).
  3. The skill sets of N candidates.

Return the indices of the selected candidates forming the smallest team.

Example:

Input:


a b c d 4 a b b c c d d

Output:
0 2

Solution (Java):

java

import java.util.*; public class MinimumTeamSelection { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] requiredSkills = scanner.nextLine().split(" "); int n = scanner.nextInt(); scanner.nextLine(); List<Set<String>> candidates = new ArrayList<>(); for (int i = 0; i < n; i++) { Set<String> skills = new HashSet<>(Arrays.asList(scanner.nextLine().split(" "))); candidates.add(skills); } scanner.close(); List<Integer> result = findMinimumTeam(requiredSkills, candidates); for (int index : result) { System.out.print(index + " "); } } private static List<Integer> findMinimumTeam(String[] requiredSkills, List<Set<String>> candidates) { int m = requiredSkills.length; Map<String, Integer> skillToIndex = new HashMap<>(); for (int i = 0; i < m; i++) { skillToIndex.put(requiredSkills[i], i); } int n = candidates.size(); int[] dp = new int[1 << m]; Arrays.fill(dp, Integer.MAX_VALUE / 2); dp[0] = 0; int[][] team = new int[1 << m][n]; for (int i = 0; i < n; i++) { int skillMask = 0; for (String skill : candidates.get(i)) { if (skillToIndex.containsKey(skill)) { skillMask |= (1 << skillToIndex.get(skill)); } } for (int j = 0; j < (1 << m); j++) { int newMask = j | skillMask; if (dp[newMask] > dp[j] + 1) { dp[newMask] = dp[j] + 1; team[newMask] = Arrays.copyOf(team[j], n); team[newMask][i] = 1; } } } List<Integer> result = new ArrayList<>(); for (int i = 0; i < n; i++) { if (team[(1 << m) - 1][i] == 1) { result.add(i); } } return result; } }

Solution (Python):

python

from itertools import combinations def find_minimum_team(required_skills, candidates): skill_to_index = {skill: i for i, skill in enumerate(required_skills)} n = len(candidates) skill_sets = [] for candidate in candidates: skill_mask = 0 for skill in candidate: if skill in skill_to_index: skill_mask |= (1 << skill_to_index[skill]) skill_sets.append(skill_mask) m = len(required_skills) min_team = None for size in range(1, n + 1): for team in combinations(range(n), size): team_mask = 0 for i in team: team_mask |= skill_sets[i] if team_mask == (1 << m) - 1: min_team = team return list(min_team) return [] # Read input required_skills = input().split() n = int(input()) candidates = [input().split() for _ in range(n)] # Get result result = find_minimum_team(required_skills, candidates) print(" ".join(map(str, result)))

3. Find a Unique Element in an Array

Problem Statement:

You are given an array containing N integers where one element appears exactly once, and all others appear twice. Find and return the unique element.

Example:

Input:
arr = [5, 3, 2, 3, 2]
Output:
5

Solution (Java):

java

import java.util.Scanner; public class UniqueElement { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = scanner.nextInt(); } scanner.close(); int unique = 0; for (int num : arr) { unique ^= num; // XOR operation } System.out.println(unique); } }

Solution (Python):

python

# Read input n = int(input()) arr = list(map(int, input().split())) # Find unique element using XOR unique = 0 for num in arr: unique ^= num # Print result print(unique)

4. Make Three Numbers Equal

Problem Statement:

You are given three integers P, Q, and R. You can perform the following operations:

  • Select two numbers and increase both by 1.
  • Decrease the third number by 1.

Determine the minimum number of operations required to make all three numbers equal.

Example:

Input:

bash

4 # Number of test cases 1 2 3 4 4 4 3 2 6 1 1 7

Output:
-1 0 -1 3

Solution (Java):

java

import java.util.Scanner; public class MakeNumbersEqual { static int minOperations(int a, int b, int c) { int sum = a + b + c; if (sum % 3 != 0) return -1; int target = sum / 3; return Math.max(0, (target - a) + (target - b) + (target - c)) / 2; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while (t-- > 0) { int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(); System.out.println(minOperations(a, b, c)); } scanner.close(); } }

Solution (Python):

python

def min_operations(a, b, c): total = a + b + c if total % 3 != 0: return -1 target = total // 3 return max(0, (target - a) + (target - b) + (target - c)) // 2 # Read input t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) print(min_operations(a, b, c))


In conclusion, these TCS NQT 2025 coding questions with solutions are designed to help you

enhance your problem-solving skills and improve your chances of acing the exam.

From basic array manipulations to more advanced problems involving recursion and dynamic

programming, these coding questions cover a wide range of topics. Make sure to practice

them thoroughly and understand the logic behind each solution.

We will continue to add more questions and updates related to the upcoming TCS NQT exams

on this blog. So, be sure to follow, stay tuned, and feel free to leave your comments or

questions below. Happy coding!


TCS NQT Apply Link :- https://nextstep.tcs.com/campus/#/

All About TCS NQT 2025 :- https://jobs.adityamewada.in/2025/02/tcs-nqt-2025-apply-now-eligibility.html

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.