Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
TCS NQT (National Qualifiers Test) is an online exam conducted by Tata Consultancy Services (TCS) for hiring fresh engineering graduates. These Coding questions assess programming skills and problem-solving abilities, evaluating a candidate's ability to write code and devise efficient solutions. This blog features TCS NQT Coding Questions.
To get the best results, we must learn to understand the most suitable inputs, the most precise output, and what arithmetic, conditional or iterative operations we must perform. Let us look at TCS NQT coding questions would look like.
TCS NQT Coding Question 2024
TCS NQT Coding Questions
Coding Round
Number of Questions
3 Questions
Time Limit
90 Minutes
Difficulty Round
Hard
Programming Logic in TCS NQT
TCS NQT Programming Logic definitely tests you for your C, C++, and Java skills, but that is not it. You must have a firm understanding of Computer Science fundamentals to answer questions in OOPS, Recursion, Threads, DSA, etc. There are an adequate number of questions based on Data Structures. Let us first revise the basic rules so that you are fully equipped to take the test:
The programming logic section is a compulsory section of the TCS NQT test, even for non-CS or IT students.
There are 10 questions in this section, with 15 minutes allotted for the same.
This section has no negative marking but is considered fairly difficult.
The cut off for the programming logic section is 6 to 7 questions with about 8-9 topics, which include:
Programming Logic section format:
Data types- There is either no or one question from data types which is relatively easy to answer if you have a clear understanding of the concept.
Functions and loops- One question with average difficulty is asked for functions and loops. They have usually coded snippets that you will have to predict output for.
Recursion, iteration- These too are traditionally mildly challenging questions that either require guessing the output or finding errors in the code.
Arrays, stacks and queues- These three closely related topics are reasonably hard to answer and need practice. However, there won’t be more than 1 question for the topic.
Trees- About 1-2 relatively tricky questions that can be solved with good practice.
Graphs, Command line programming and Greedy algorithms-1 challenging questions for all three topics. Solving practice questions for them helps understand them better.
We looked at a few recent tests and tried to frame similar questions for you, for which you can check your answers and read the explanations to have a clear understanding of the concept used.
Question 1:
Predict the output of the following code snippet:
#include <stdio.h>
int main()
{
int i=3;
switch(i)
{
case 0: printf("Purple");
break;
case 1+1: printf("Blue");
break;
case 7/2: printf("Yellow");
break;
case 3%2: printf("Black");
break;
}
return 0;
}
Initially, the value of i is 3. We perform a switch action, which can only be performed on char or int data types. For any more complex case than 0, the case takes anything up to the colon as a single entity.
Therefore, 1+1=2, 7/2=3(quotient) since it is of integer data type, 3%2=1(remainder). Now, there is a break after any case that is acted upon. This takes the user out of the switch once the case is executed so that there is no repetition.
Since the value of i is 3, it will go to case 3, i.e., “case 7/2:” and then the switch will break. The simple output for this code would thus be Yellow.
Question 2:
The range of a 10-bit unsigned integer is:
1. 0-1024
2. 0-1000
3. 0-1048
4. 0-1023
Answer
0-1023
Explanation
We know that the number of bits here is 10 and for every bit, there are 2 possible values(0 and 1) Since it is an unsigned integer, no bit is used to represent the sign and all 10 bits will represent the magnitude. Now, the total possible number would be 2^n=2^10=1024. Starting from 0, that gives us the range: 0-1023.
Question 3:
In the following code, identify the line with an error.
# include<stdio.h> //line 1
# include<conio.h> //line 2
void main() //line 3
{ //line 4
float num1 = 100.00; // line 5
{ // line 6
auto float num1 = 675.29; // line 7
{ // line 8
auto float num2 = 325; //line 9
printf("\n%f %f", num1); //line 10
num2++; // line 11
} // line 12
num1++; // line 13
printf("\n%f %f", num2, num1); // line 14
num1++; // line 15
} // line 16
printf("\n%f", num1); //line 17
} // line 18
Since ‘num2’ is declared locally in an inner block, its scope doesn’t extend outside the block where it is accessed. To fix the code, we must declare ‘num2’ globally to give it global scope.
Question 4:
#include <stdio.h>
int main()
{
double num = (0.4, 4.7, 7.4);
printf("%f", num);
return 0;
}
The bracket operator is executed before the assignment operator due to higher precedence. The result will always be from the last expression assigned when evaluated left to right.
Question 5:
The in-order traversal of a binary tree is M J N H R K S, and its pre-order traversal is H J M N K R S. According to this, what would be the post-order traversal of the binary tree?
1. M J N R K S H
2. H J K M N R S
3. M N J R S K H
4. R S K H M N J
Answer
3. M N J R S K H
Explanation
The binary tree is shown according to the in-order and preorder traversal. We can build the binary tree by considering its inorder transversal and pre-order transversal. The creation is as follows:
We will need to assume that the initial value of packets is 0. Now, there is no initialization or condition meaning that the for loop will run forever. However, a break statement later in the loop shows that if the ‘if’ condition is true, then the loop will terminate. First, the loop will print 0. Now, the next step is crucial.
Since there is a post-increment inside the if loop, we will check the condition first and then increment. The value of packets is 0, which is not equal to 6. The loop will perform a post-increment to 1 from the ‘if’ condition and go for iteration again. Now it will be incremented from the ‘for’ loop, too. Therefore, the value of packets will become 2. Again, we check the if condition and perform post-increment such that packages=3. It will go back to the for loop, increment and print 4. The loop will repeat in this manner until packets become precisely 6. Therefore the output would be 0, 2, 4 and 6.
Question 7:
What type of output would the following code produce?
#include <stdio.h>
int main()
{
int num = 5;
printf("%p\n", &num);
return 0;
}
People tend to get confused since there is no condition for ‘if’. However, it is straightforward. The value of ‘a’ is initialized as 0. Now, if the result of whatever we write is 0, it is considered false, while every non-zero result will be true. In post-increment, the value is checked before updation. So the condition will be false, and the else condition will print Goodbye.
Question 9:
What is the syntax for command-line arguments?
1. int main(char c, int arg)
2. int main(int var, char*argv[])
3. int main(int v, char c)
4. int main(char*arv[], int arg[])
Answer
2. int main(int var, char*argv[])
Explanation
The syntax for command-line arguments is int main(int var, char*argv[]), where var is a positive integer variable to store the number of arguments passed by users (including the program name). The ‘argv’ or the argument vector, on the other hand, is an array for character pointers and lists all arguments. ‘argv[0] is the program name and all elements till argv[var-1] are command-line arguments.
Question 10:
Arrays are also known as:
1. Identical variables
2. Variable collectives
3. Similar quantity variables
4. Subscripted variables
Answer
4. Subscripted variables
Explanation
Since all elements in the array can be identified under the same name, with the index value (subscript value), arrays can also be called subscripted variables.
Question 11:
A user is trying to pop an element from some empty stack. Such a condition is exclusively called:
1. Underflow condition
2. Overflow condition
3. Garbage collection
4. Empty collection
Answer
1. Underflow condition
Explanation
In case a user tries to delete an element from a stack containing no elements at all, the condition is termed an underflow condition.
Question 12:
A given tree’s height starts from 0. Trisha wants to know the number of nodes in that tree. What do you think would be the number of nodes in a tree with ‘h’ height?
1. 2^h
2. 0
3. (h^2 – 1)
4. (2^h+1 – 1)
Answer
4. (2^h+1 – 1)
Explanation
We know from the formula itself that: if h starts from 0, there will be (2^h+1 – 1) nodes; if h starts from 1, there will be (2^h – 1)nodes in the tree.
Question 13:
What is the time complexity for a merge-sort algorithm?
1. O(n)
2. O(log n)
3. O(n log(n))
4. O(n^2)
Answer
3. O(n log n)
Explanation
Merge sort divides the array into two halves and then merges both halves in linear time. Therefore the worst, average and best case time complexity will be O(n*Log n).
Question 14:
How many moves are needed to solve the Tower of Hanoi puzzle?
1. 2^(n)-1
2. 2^(n)+1
3. 2^n
4. n^2
Answer
1. 2^(n)-1
Explanation
In the Tower of Hanoi, for disc 1, we need 1 move. For disc 2, we need 3 moves and for disc 3 we need 5 moves. Hence, for n discs, we need 2^(n)-1 moves.
Question 15:
What type of value does a dangling pointer point to?
1. Points to a null value
2. Points to 0 value
3. Points to a garbage value
4. Both 1 and 2
Answer
3. Points to a garbage value
Explanation
Unreferenced objects or garbage value is pointed at by a dangling pointer.
Yes, TCS NQT (National Qualifier Test) typically includes coding questions as part of its assessment. Candidates are tested on their programming skills and problem-solving abilities during the coding section of the test.
How many times can you appear for TCS NQT?
There is no limit on the number of attempts but failing the written exam will mean not being able to write the exam again for the next 6 months. After that period, you can retake the exam.
Can we use Python in TCS NQT?
While Python is definitely allowed in the TCS NQT exam, it is discouraged because the TCS Python compiler usually takes very long to compile the code, which is a problem since it is not time efficient.
What is the average difficulty of the Programming Logic section?
The programming logic section in TCS NQT is considered fairly complex and requires good practice before taking the test. However, with an adequate understanding of concepts, one can certainly clear the cut off of 7 questions in this section.
Conclusion
In this article, we learned about the format, topics and concepts for the Programming logic section in TCS NQT. We solved questions similar to the previous papers and explanations for the answers so that the concepts are concrete in our knowledge.