Ad Code

NEW POST

6/recent/ticker-posts

TCS NQT 2025 Coding Questions with Solutions

https://ift.tt/bXLIMj4

Preparing for TCS NQT 2025? Get a list of the most asked TCS NQT 2025  coding questions with solutions to boost your chances of clearing the exam. These TCS NQT 2025 coding questions with solutions cover important topics like arrays, strings, recursion, and dynamic programming. Whether you’re a fresher or an experienced candidate, practicing these TCS NQT 2025 coding questions with answers  will help you ace the exam. Stay ahead with TCS NQT 2025 most asked coding questions and enhance your problem-solving skills. Start your TCS NQT 2025 coding preparation now!

TCS NQT 2025 Coding Questions with Solutions

1. Sum of Integers in a Range

Problem Statement:

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

Example:

Input:
0 3
Output:
6
Explanation:
0+1+2+3 = 6

Solution in 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 in Python:

# Read input
m, n = map(int, input().split())

# Calculate sum
result = sum(range(m, n + 1))

# Print result
print(result)

Google,IBM,Cisco free Courses : Click Here

2. Minimum Team Selection to Cover Required Skills

Problem Statement:

You are given a list of required skills and a list of candidates, where each candidate has a subset of skills. Your task is to find the smallest possible team such that all required skills are covered.

You will be given:
1. Required skills list
2. Number of candidates (N)
3. Skillsets of N candidates

Return the indices of selected candidates forming the smallest team.

Example:

Input:
a b c d
4
a b
b c
c d
d
Output:
0 2

Input:
a b c
3
a
b c
c
Output:
0 1

Solution in 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 in 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
temp = input().split()
required_skills = temp
n = int(input())
candidates = [input().split() for _ in range(n)]

# Get result
result = find_minimum_team(required_skills, candidates)
print(” “.join(map(str, result)))

 

SBI Internship for anyone 19,000 rs/Monthly : Click Here

3. Find a Unique Element in an Array

Problem Statement:

You are given an array containing N integers where only one element is unique (appears exactly once), while all other elements appear twice. Find and return the unique element.

Example:

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

Solution in 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 in 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 operation any number of times:
• Select any two numbers and increase both by 1.
• Decrease the third number by 1.
Your task is to determine the minimum number of operations required to make all three numbers equal.

Example:

Input:
4  # Number of test cases
1 2 3
4 4 4
3 2 6
1 1 7
Output:
-1
0
-1
3

Solution in 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 in 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))

TCS NQT Coding Preparation Tips

  1. Understand Problem Statements Clearly – Read and analyze the given problem statement before writing code.

  2. Optimize Your Code – Use efficient data structures and algorithms to reduce time complexity.

  3. Practice Previous Year Questions – Solve TCS NQT past papers to understand the exam pattern.

  4. Improve Speed & Accuracy – Use online coding platforms like LeetCode, CodeChef, and HackerRank to practice.

  5. Revise Key Concepts – Focus on loops, recursion, arrays, strings, sorting, and bitwise operations.

These TCS NQT coding questions help in mastering key concepts required for campus placements. Keep practicing and refining your problem-solving skills!

Stay tuned for more TCS NQT coding solutions, interview tips, and preparation strategies!

The post TCS NQT 2025 Coding Questions with Solutions appeared first on placementdriveinsta.in.

Post a Comment

0 Comments