Back

TCS NQT Coding Questions for 2024 - Important Topics, Format

22 Oct 2024
3 min read

The TCS NQT (National Qualifier Test) is a crucial assessment for aspiring candidates looking to secure a position in Tata Consultancy Services (TCS). Among various evaluation components, coding questions play a significant role in assessing candidates' programming skills. In this article, we will explore the structure, important topics, and types of coding questions asked in the TCS NQT.

What are TCS NQT Coding Questions

TCS NQT coding questions are designed to evaluate a candidate's problem-solving and coding abilities. These questions can vary in complexity, testing a range of skills from basic programming constructs to advanced algorithmic problem-solving. Candidates typically encounter problems that require them to write code in popular programming languages like C, Java and Python.

How Many Rounds Does TCS NQT Have?

The TCS NQT typically consists of multiple rounds, including:

  • Aptitude Test: This initial round assesses logical reasoning, quantitative aptitude, and verbal ability.
  • Coding Round: Candidates are required to solve coding questions within a specified timeframe. This is the key focus for many aspirants.
  • Technical Interview: Following the coding round, selected candidates often face technical interviews where they may be asked to explain their solutions or related technical questions.
  •  HR Interview: The final round usually involves an interview focusing on soft skills and cultural fit.

TCS NQT Important Topics and Syllabus

Here are the topics asked in TCS NQT coding questions:

Quantitative Aptitude

Foundation Section (Easy-Medium)

  • Area & Mensuration
  • Data Interpretation
  • HCF & LCM
  • Linear Equations
  • Percentage
  • Simple Interest
  • Profit and Loss
  • Speed, Distance, Time
  • Time & Work
  • Number System
  • Compound Interest
  • Ratio and Proportion
  • Mixtures
  • Probability
  • Permutation and Combination

Advanced Section (Hard)

  • Averages
  • Geometry
  • HCF & LCM
  • Logarithms
  • Mensuration
  • Number System
  • Permutation and Combination
  • Puzzles
  • Probability
  • Progressions
  • Simple & Compound Interest
  • Time, Speed, Distance
  • Time & Work

Reasoning Ability

Foundation Section (Medium)

  • Analogies
  • Attention to Detail
  • Blood Relations
  • Coding and Decoding
  • Cuts and Unfolds
  • Data Arrangements
  • Syllogisms
  • Unboxing a Cube
  • Venn Diagrams
  • Visual Reasoning
  • Statement Assumption
  • Statement Conclusion
  • Seating Arrangements

Advanced Section (Hard)

  • Data Arrangements
  • Cuts, Folds, and Cubes-based Questions
  • Puzzles
  • Syllogisms
  • Spatial Reasoning
  • Statement Assumption
  • Statement Conclusion
  • Visual Reasoning
  • Venn Diagrams
  • Seating Arrangements

Verbal Ability (Easy-Medium)

  • Error Identification
  • Fill in the Blanks (Prepositions, Articles, Tenses, Conjunctions)
  • Reading Comprehension
  • Sentence Correction
  • Sentence Completion
  • Sentence/Paragraph Rearrangements
  • Synonyms & Antonyms

Advanced Coding

  • Advanced Coding
  • Algorithms
  • Control Statements
  • Data Structures (Linked List, Stack, Queue, Trees, Graphs)
  • Flow Control Loops
  • Functions
  • Looping Statements
  • Matrix Operations and Set Theory
  • Multidimensional Arrays
  • Number Series, Pattern Series
  • Recursion
  • Scenario and Logical-Based Problems
  • Shortest Path Calculation Logic
  • String Operations (Backward and Forward Shift)
  • Time and Space Complexity

TCS NQT Coding Question and Answers 2024

Here, we have provided some TCS NQT coding questions and answers to help you understand the format and type of questions you may encounter during the assessment:

1. In a bustling chocolate factory, workers are busy packing chocolates into packets. Each packet is represented by an array of integers, where `0` signifies an empty packet. The factory manager has tasked you with finding all the empty packets and pushing them to the end of the array.

Example

Input
N = 8
arr = [4, 5, 0, 1, 9, 0, 5, 0]
Output
4 5 1 9 5 0 0 0

C

#include <stdio.h>

void moveZeroes(int arr[], int n) {
    int count = 0; // Count of non-zero elements
    for (int i = 0; i < n; i++)
        if (arr[i] != 0)
            arr[count++] = arr[i]; // Move non-zero elements forward

    while (count < n)
        arr[count++] = 0; // Fill remaining with zeros
}

int main() {
    int arr[] = {4, 5, 0, 1, 9, 0, 5, 0};
    int n = sizeof(arr) / sizeof(arr[0]);

    moveZeroes(arr, n);
    for (int i = 0; i < n; i++)
        printf("%d ", arr[i]);
    return 0;
}

Java

public class MoveZeroes {
    public static void moveZeroes(int[] arr) {
        int count = 0; // Count of non-zero elements
        for (int i = 0; i < arr.length; i++)
            if (arr[i] != 0)
                arr[count++] = arr[i];

        while (count < arr.length)
            arr[count++] = 0; // Fill remaining with zeros
    }

    public static void main(String[] args) {
        int[] arr = {4, 5, 0, 1, 9, 0, 5, 0};
        moveZeroes(arr);
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}

Python

def move_zeroes(arr):
    count = 0  # Count of non-zero elements
    for num in arr:
        if num != 0:
            arr[count] = num
            count += 1
            
    while count < len(arr):
        arr[count] = 0
        count += 1

arr = [4, 5, 0, 1, 9, 0, 5, 0]
move_zeroes(arr)
print(arr)

2. Jack loves Sundays. He wants to know how many Sundays will occur in a month starting on any given day. Given the starting day and the total number of days in the month, your task is to find out the number of Sundays.

Input

  • A string indicating the first day of the month (e.g., "mon") and an integer representing the total number of days in that month.

Output

  • The number of Sundays in that month.

Example

Input
mon
13

Output
2

C

#include <stdio.h>
#include <string.h>

int main() {
    char s[4];
    scanf("%s", s);
    int days;
    scanf("%d", &days);

    char weekdays[][4] = {"mon", "tue", "wed", "thu", "fri", "sat", "sun"};
    int offsets[] = {6, 5, 4, 3, 2, 1, 0};
int start = -1;
    for (int i = 0; i < 7; i++) {
        if (strcmp(s, weekdays[i]) == 0) {
            start = offsets[i];
            break;
        }
    }
    int sundays = 0;
    for (int i = 1; i <= days; i++) {
        if ((start + i) % 7 == 0) {
            sundays++;
        }
    }
    
    printf("%d\n", sundays);
    return 0;
}

Java

import java.util.Scanner;

public class CountSundays {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        String startDay = scanner.next();
        int days = scanner.nextInt();

        String[] weekdays = {"mon", "tue", "wed", "thu", "fri", "sat", "sun"};
        int[] offsets = {6, 5, 4, 3, 2, 1, 0};

        int start = -1;
        for (int i = 0; i < 7; i++) {
            if (startDay.equals(weekdays[i])) {
                start = offsets[i];
                break;
            }
        }

        int sundays = 0;
        for (int i = 1; i <= days; i++) {
            if ((start + i) % 7 == 0) {
                sundays++;
            }
        }

        System.out.println(sundays);
    }
}

Python

def count_sundays(start_day, days):
    weekdays = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
    offsets = [6, 5, 4, 3, 2, 1, 0]

    start = -1
    for i in range(7):
        if start_day == weekdays[i]:
            start = offsets[i]
            break

    sundays = 0
    for i in range(1, days + 1):
        if (start + i) % 7 == 0:
            sundays += 1

    return sundays

# Input reading
start_day = input().strip()
days = int(input())
print(count_sundays(start_day, days))

3. Joseph has been pondering about numbers in his digital logic class. He found a peculiar challenge where he must take a positive integer, convert it to binary, toggle all its bits starting from the most significant bit, and find the resulting decimal value. Can you assist him in this toggle challenge?

Input

A single integer 𝑁.

Output

The integer value after toggling all bits.

Example

Input:
10

Output:
5

C

#include <stdio.h>
#include <math.h>

int main() {
    int n;
    scanf("%d", &n);
    if (n == 0) {
        printf("1\n");
        return 0;
    }
    int k = (1 << (int)(log2(n) + 1)) - 1;
    printf("%d\n", n ^ k);
    return 0;
}

Java

import java.util.Scanner;

public class ToggleChallenge {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int k = (1 << (Integer.SIZE - Integer.numberOfLeadingZeros(n))) - 1;
        System.out.println(n ^ k);
    }
}

Python

n = int(input())
bits = (1 << n.bit_length()) - 1  # Mask for toggle
print(n ^ bits)

4. You are given an array consisting of only three distinct integers: 0, 1, and 2. Your task is to sort the array in a single pass, such that all 0's come first, followed by all 1's, and then all 2's.

Implement a function to achieve this and demonstrate its usage with an example.

Input

  • The first line contains an integer 𝑛(1 ≤ n ≤ 100), the number of elements in the array.
  • The second line contains n integers, each of which can be either 0, 1, or 2.

Output

  • Print the sorted array in a single line.

Example

Input
5
2 0 1 2 0

Output

0 0 1 2 2

C

#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

void sortArray(int arr[], int size) {
    int low = 0, mid = 0, high = size - 1;
    while (mid <= high) {
        if (arr[mid] == 0) {
            swap(&arr[low], &arr[mid]);
            low++;
            mid++;
        } else if (arr[mid] == 1) {
            mid++;
        } else {
            swap(&arr[mid], &arr[high]);
            high--;
        }
    }
}

int main() {
    int n;
    scanf("%d", &n);
    int arr[n];
    
    for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
    }
    
    sortArray(arr, n);
    
    for (int i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}

Java

import java.util.Scanner;

public class SortArray {
    public static void swap(int[] arr, int a, int b) {
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }

    public static void sortArray(int[] arr) {
        int low = 0, mid = 0, high = arr.length - 1;
        while (mid <= high) {
            if (arr[mid] == 0) {
                swap(arr, low, mid);
                low++;
                mid++;
            } else if (arr[mid] == 1) {
                mid++;
            } else {
                swap(arr, mid, high);
                high--;
            }
        }
    }

    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();
        }
        
        sortArray(arr);
        
        for (int i : arr) {
            System.out.print(i + " ");
        }
        scanner.close();
    }
}

Python

def swap(arr, a, b):
    arr[a], arr[b] = arr[b], arr[a]

def sort_array(arr):
    low, mid, high = 0, 0, len(arr) - 1
    while mid <= high:
        if arr[mid] == 0:
            swap(arr, low, mid)
            low += 1
            mid += 1
        elif arr[mid] == 1:
            mid += 1
        else:
            swap(arr, mid, high)
            high -= 1

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split()))
    
    sort_array(arr)
    
    print(" ".join(map(str, arr)))

5. In a mystical land, a wise sage collects gemstones. Each time he collects a new gemstone, he wonders how many of them are more radiant than any he has collected before. Can you help the sage count these radiant gems?

Input

  • The number of gemstones n.
  • The radiance values of the gemstones.

Output

  • The count of gemstones that are more radiant than all previously collected ones.

Example

Input:
5
1 3 2 4 5

Output:
4

C

#include <stdio.h>
#include <limits.h>

int main() {
    int n;
    scanf("%d", &n);
    int count = 0, current_max = INT_MIN, value;

    for (int i = 0; i < n; i++) {
        scanf("%d", &value);
        if (value > current_max) {
            current_max = value;
            count++;
}
    }

    printf("%d\n", count);
    return 0;
}

Java

import java.util.Scanner;

public class RadiantGems {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0, currentMax = Integer.MIN_VALUE;

        for (int i = 0; i < n; i++) {
            int value = scanner.nextInt();
            if (value > currentMax) {
                currentMax = value;
                count++;
            }
        }

        System.out.println(count);
        scanner.close();
    }
}

Python

n = int(input())
count = 0
current_max = float('-inf')

for _ in range(n):
    value = int(input())
    if value > current_max:
    current_max = value
        count += 1

print(count)

Conclusion

In conclusion, to prepare for TCS NQT coding questions, it is important to have a solid understanding of programming fundamentals and to practice coding exercises continuously. By focusing on key topics and using available resources, candidates can enhance their chances of success in this competitive exam.

Frequently Asked Questions

1. What are the common programming languages used for TCS NQT coding questions? 

Candidates can use C, Java, Python, and other popular languages to solve coding questions in TCS NQT.

2. Are there any advanced coding questions in TCS NQT? 

Yes, candidates may encounter advanced coding questions that require a deeper understanding and implementation of algorithms and data structures.

Read More Articles

Talk to career expert