Open In App

TCS NQT Coding Questions & How Coding Task Evaluated in TCS NQT

To know more about the TCS NQT: TCS NQT – National Qualifier Test

1. How to solve the Coding Section in TCS NQT 2022? 

STEP by STEP guide to solving the coding section in TCS NQT 2022.

STEP 1: Understanding the storyYou are given 30 minutes to write a program and clear all the test cases. Of this, spend the first five to six minutes on understanding the story given and figuring out what needs to be calculated. If your English is not very strong, you need to spend more time in reading and understanding the task. Don’t jump into typing your program before you understand what is going on.

These are the points that you need to understand from the task.

STEP 2: Reading the inputs Once you know what is needed, we need to think in terms of how you write the code. At this time we don’t know how to find the answer. But we know how to take the inputs. So, the first part of the program is to read the value of N, declare an array and read N-1 values into the array. Even though the task keeps changing, reading a set of values in a loop is required in many programs. You will need to practice several programs so that you won’t waste your time in simple tasks like this in the actual exam.

 

STEP 3: Cracking the core logic

The next step is to figure out how to convert this data into an answer. By the time we reach this step in the exam, we should have about 20 minutes left. Let’s race against the time. Consider the example given in the question. We see that the denomination Rs.2 appears two times, Rs.1 appears two times and Rs.5 appears three times. Why is it so? We know that originally all these are present an even number of times. But, one of the coins got lost and that is the number which appears an odd number of times. In this example, we can infer that originally, there were four coins with Rs. 5 but one of them fell down. That is why we finally have three Rs.5 coins instead of four Rs.5 coins. Here is a direct way of solving this problem. Towards the end of this article, we will see a more efficient way of solving the same problem.

 

Method 1:

When we divide an Odd number with 2, we get 1 as remainder. This can be obtained using the % operator.

Method 2: Once we realize that we need to find the number which is occurring an Odd number of times, some of us can come up with an alternative method to identify it. This method is based on the EXOR operation which is a bit-wise operation performed using the ^ symbol. Here is the Truth table for XOR operations. Operands Result:

0 ^ 0 0 
0 ^ 1 1 
1 ^ 0 1 
1 ^ 1 0

From the above Truth table, we can conclude that N ^ N = 0, 0 ^ N = N. Let’s say we have 3 integers A, B and C. Here are a few interesting results from EXOR.

A^A=0 
A^B^A = A^A^B = B 
A^B^C^B^A^C = 0

Once we know this, we can go ahead and implement this in the code. We just need to take a temporary variable to store the result. Let’s call this E and initialize it to 0. We then need to go through a loop and perform EXOR on all the given elements. The final value of EXOR is the answer we need. 2. What is TCS NQT 2022?

Step 4: Validating the code

The remaining time in the exam can be spent in verifying that the code clears all the test cases. In case it fails, you can try giving your own inputs to find out when it is failing and then try to correct the algorithm. In TCS NQT 2022, you might not have a big penalty if your code is slow. So, it makes a lot of sense for you to write working code before you worry about efficiency.

 

TCS NQT 2022(https://learning.tcsionhub.in/hub/national-qualifier-test/) is the exam conducted by TCS for recruiting freshers who are going to graduate in the year 2022. Make sure that you understand the Eligibility criteria for the test, the syllabus and test pattern.

3. What is the Coding section in NQT 2022?

The coding section of the TCS NQT 2022 has one question which is usually in the form a Case study or a Story. At the end of the Caselet, they will ask us to write a program which takes the input in a particular format and produces the output as per the required format. 4. What are the other rules for the Coding section?

You can attempt the coding task in any of the 5 languages given by TCS. These are C, C++, Java, Python and Perl. You have a total of 30 minutes to solve this question. Here are the most important points to know about before you attempt the coding section of TCS NQT 2022.

5. How is the coding task evaluated?

The TCS NQT 2022 is attempted by lakhs of students. The examiners are not going to read everyone’s code. Instead, they will use a computerized evaluation which will automatically assign score based ONLY ON THE OUTPUT. The main part of the coding section is “Test Cases”. Your code will be Validated against test cases. You will be given partial marks based on how many test cases are cleared.

6. Do I need to make my program so efficient?

While it is always good to write efficient programs you need to control your greed. Before you worry about efficiency, you need to ensure that your program clears at least some of the test cases. Finally, nobody reads your code – they just look at the number of test cases. Make sure that your code clears as many test cases as possible. However, if you know an efficient method, there is no reason for you to not use it. Go ahead, give it best shot. This is your playground.

7. In which language should I write the code?

The advantage of choosing C, C++ and Java over scripting languages is that the compiler is very strict. The probability of any mistakes being found by the compiler is very high which means the probability of validating against the test cases is also high. On the other hand, in scripting languages like Python or Perl the probability of finding mistakes by compiler is not fruitful. Some of your coding mistakes might percolate till the time you go into the compiler stage. As we keep telling, don’t try to learn a new programming language now. Stick with a language that you already know. Build your confidence by practicing multiple tasks using it.

 

8. Is it necessary to Validate Against Test Cases?

TCS NQT 2022 has introduced the facility of validating your solution code against the actual test cases. Make sure that your code is clearing them. Keep tweaking it until you are done. However, in the last 2 minutes you need to ensure that your code is stable. Stop making any further changes. Read your code a few times to ensure that you haven’t done anything stupid in your excitement.

 

9. Where can I get more questions like this?

You can prepare yourself for the TCS NQT with us by following this course TCS NQT Preparation Test Series.


Article Tags :