TCS NQT Coding Questions With Answers 2021

We are going to discuss TCS NQT Coding questions with answers in this post. But before we move forward, let’s have a look at what the TCS NQT syllabus

Firstly, let me brief you about TCS NQT. Basically, TCS National Qualifier Test (TCS NQT) is a multi-level assessment to assess the following competencies and skills. TCS NQT is an Ability Test that assesses your competencies and skills. 

Secondly, each student who completes the TCS National Qualifier Test (TCS NQT) gets an NQT Score. The NQT (Cognitive Skills) Score is applicable for all industries and job roles. You are then eligible to apply for the TCS National Qualifier Test (TCS NQT) and should meet the below criteria:

  1. UG, PG and Diploma students who are in their pre-final and final year of study.
  2. Freshers with less than 2 years of experience.
  3. Age limit – minimum 18 years and maximum 28 years.
TCS NQT Test Pattern

If you subscribe it will boost our self to provide ads-free high quality content

TCS NQT Coding Syllabus

You can expect Questions from the following concepts –

  1. Number Series Printing Example – 1, 2, 5, 4, 25, 16, 125, 64 …… This series is a mixture of power of 2 and power of 5. You have to print the series.
  2. Strings  Example – Read a string and convert all the uppercases to $ sign and all lower cases to & sign and print the output.
  3. Matrix Finding Highest sum for a row in a given matrix
  4. Pythagoras Triplets
  5. LCM of 3 numbers etc.

Now, let me explain to you about the coding section. This section includes 10 programming MCQs and 2 hands-on questions to be completed in 45 minutes. Languages allowed are C/ C++/ Java/ Python/ PERL. To gain max opportunities of cracking this section, you must try to clear all of the possible test cases. GeeksToCode is here to make sure that you qualify with flying colors in this section.

First and foremost, you should select a programming language that you are more comfortable with. C programming and python are most common. An IMPORTANT point to be noted is that the TCS compiler takes 5 seconds to compile. Thus, one must avoid compiling the program multiple times. As it just leads to loss of time.

TCS NQT Coding questions – Important instructions

1) 10 MCQs. First hands-on question-15 minutes and the second question 30 minutes.
2) Choice of C / C++ / Java / Perl / Python 3.
3) Provided an IDE to debug.
4) For Java, the class name should be named Maze.
5) The input to the program either through STDIN / Command line arguments, as per
the instructions.
6) The program should write the output to STDOUT.
7) Public and private test cases based evaluation.

Other important points to note

1) While printing the output there should be no leading or trailing spaces printed.
2) no other text should be printed other than the required output,
3) If the output is a number, no leading sign must be printed unless it is a negative
number.
4) No scientific notation (3.9265E + 2).
5) All floating-point numbers must contain that many decimal places as mentioned in
the question.

Here, we have provided a list of basic programs which you should be well-versed with as these programs will create your basics and help you to solve the questions easily.

TCS NQT Coding Section

TCS NQT Basic 20 Coding Questions List

  1. Reverse a String.
  2. Reverse a Number.
  3. Prime Number.
  4. Greatest among 10 numbers.
  5. Fibonacci Series.
  6. HCF / GCD.
  7. Decimal to Binary & vice versa
  8. Armstrong Number.
  9. Swap 2 numbers.
  10. Concatenate 2 strings.
  11. Average of Two Numbers.
  12. Sum of Digits of a number.
  13. Binary to Decimal and vice versa
  14. Factorial of a Number.
  15. Square Root of Prime Number.
  16. Odd-Even Number.
  17. Binary to Octal and Decimal to Octal.
  18. Check Leap Year.
  19. Area of Circle/Triangle
  20. Checking Palindrome (Number or String)

These are some of the most important and basic TCS NQT coding questions which form a base to solve other problems. Now, let’s head towards some previous year coding questions asked in TCS NQT –

Question 1: Oddly Even

Given a maximum of 100 digit numbers as input, find the difference between the sum of odd and even position digits.

Input 1:

 4567

Expected output: 

2

Explanation

Here, the sum of odd position digits 4 and 6 is 10. The Sum of even position digits 5 and 7 is 12. The difference is 12-10=2.

Input #2: 

9834698765123

Code (Python)

num=input()
Evensum=int(0)
Oddsum=int(0)
for i in range(0,len(num)):
if(i%2==0):
Evensum+=int(num[i])
else:
Oddsum+=int(num[i])
print(int(abs(Evensum-Oddsum)))

This was an easy to understand problem, if one has practiced the above basic coding questions.

Question 2: Caesar Cipher

The Caesar cipher is a type of substitution cipher in which each alphabet in the plaintext or messages is shifted by a number of places down the alphabet.
For example, with a shift of 1, P would be replaced by Q, Q would become R, and so on.

To pass an encrypted message from one person to another, it is first necessary that both parties have the ‘Key’ for the cipher so that the sender may encrypt and the receiver may decrypt it.
Key is the number of offsets to shift the cipher alphabet. Key can have basic shifts from 1 to 25 positions as there are 26 total alphabets.

As we are designing custom Caesar Cipher, in addition to alphabets, we are considering numeric digits from 0 to 9. Digits can also be shifted by key places.
For Example, if a given plain text contains any digit with values 5 and key =2, then 5 will be replaced by 7, “-”(minus sign) will remain as it is. Key-value less than 0 should result in “INVALID INPUT”

Input 1:
Enter your PlainText: All the best
Enter the Key: 1

Expected Output : The encrypted Text is: Bmm uif Cftu

Explanation

The function Caesar(int key, String message) will accept plaintext and key as input parameters and returns its ciphertext as output.

Code (Python)

def ceaser(text,key):
    result = ""
   # transverse the plain text
    for i in range(len(text)):
        char = text[i]
      # Encrypt uppercase characters in plain text
        if (char.isupper()):
            result += chr((ord(char) + key-65) % 26 + 65)
      # Encrypt lowercase characters in plain text
        elif (char.islower()):
            result += chr((ord(char) + key - 97) % 26 + 97)
        elif(char.isdigit()):
            result += str(int(char) + key)
        elif(char == '-'):
            result += '-'
        elif (char.isspace()):
            result += " "
    return result
#check the above function
text = input("Enter your plain text:")
key = int(input("Enter the key:"))
print(ceaser(text,key))

Question 3: Chain Marketing

Chain Marketing Organization has a scheme for income generation, through which its members generate income for themselves. The scheme is such that suppose A joins the scheme and makes R and V join this scheme then A is Parent Member of R and V who are child Members. When any member joins the scheme then the parent gets a total commission of 10% from each of its child members.

Child members receive a commission of 5% respectively. If a parent member does not have any member joined under him, then he gets a commission of 5%.
Take the name of the members joining the scheme as input.
Display how many members joined the scheme including parent members. Calculate the Total commission gained by each member in the scheme. The fixed amount for joining the scheme is Rs.5000 on which commission will be generated
SchemeAmount = 5000

Example 1: When there are more than one child members 
Input : (Do not give input prompts. Accept values as follows.

Hannah                     //Enter parent Member as this
Y                           //Enter Y if  Parent member has child members otherwise enter N
Rocky, Shahrukh        //Enter names of child members of Amit in comma separated


Output: (Final Output must be in format given below.)

TOTAL MEMBERS:3
COMISSION DETAILS
Hannah: 1000 INR
Rocky :250 INR
Shahrukh: 250 INR

Example 2: When there is only one child member in the hierarchy
Input :
Hannah
Y
Rocky
Output:
Total Members: 2 
Commission Details
Hannah: 500 INR
Rocky: 250 INR

Code (Python)

parent = input()
Yes_No = input()
if Yes_No == "N":
    print("TOTAL MEMBERS:1\nCOMMISSION DETAILS\n{0}: 250 INR".format(parent))
elif Yes_No == "Y":
    child=list(map(str,input().split(",")))
    print("TOTAL MEMBERS:{}".format(len(child)+1))
    print("COMMISSION DETAILS \n{0}:{1} INR".format(parent,len(child)*500))
    for i in child:
        print("{0}:250 INR".format(i))

Question 4: Number Series with a Twist

Consider the series : 0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8

This series is a mixture of 2 series, all the odd terms in this series form even numbers in ascending order and every even terms is derived from the previous term using the formula (x/2)

Write a program to find the nth term in this series.

  1. The value of n is a positive integer that should be read from STDIN and the nth term that is to be calculated by the program should be written to STDOUT.
  2. Other than the value of the nth term, no other characters /strings or message should be written to STDOUT.

For example

If n=10, the 10th term in the series is to be derived from the 9th term in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be printed to STDOUT.

You can assume that the n will not exceed 20,000.

Note: TCS often asks such questions on twisted number series, so make sure you have a good understanding about the logic.

Code (Python)

n = int(input('enter the number:'))
a=0
b=0
for i in range(1,n+1):
    if(i%2!=0):
        a= a+2
    else:
        b= b+1
if(n%2!=0):
    print('{}'.format(a-2))
else:
    print('{}'.format(b-1))

Code ( C )

#include<stdio.h>

int main()
{
    int i, n, a=0, b=0;
    printf("enter number : ");
    scanf("%d",&n);
    
    
    for(i=1;i<=n;i++)
    {
        if(i%2!=0)
        {
            if(i>1)
                a = a + 2;
        }
        else
        {
            b = a/2;
        }
    }

    if(n%2!=0)
    {
        printf("%d",a);
    }
    else
    { 
        printf("%d",b);
    }
    
    return 0;
}

Question 5: Estimating the cost

Problem Statement – We want to estimate the cost of painting a property. Interior wall painting cost is Rs.18 per sq.ft and exterior wall painting cost is Rs.12 per sq.ft.

Take input as
1. Number of Interior walls
2. Number of Exterior walls
3. Surface Area of each Interior 4. Wall in units of square feet
Surface Area of each exterior wall in units of square feet.

Note – If a user enters zero as the number of walls then skip surface area values as user may don’t  want to paint that wall.

Calculate and display the total cost of painting the property

Example 1:

6
3
12.3
15.2
12.3
15.2
12.3
15.2
10.10
10.10
10.00
Total estimated Cost : 1847.4 INR

Code (Python)

interior_walls = int(input())
exterior_walls = int(input())
if interior_walls:
    int_walls = []
    for i in range(interior_walls):
        int_walls.append(float(input()))

if exterior_walls:
    ext_walls = []
    for i in range(exterior_walls):
        ext_walls.append(float(input()))
if exterior_walls < 0 or interior_walls < 0:
    print(“Invalid Input”)
    exit()
if exterior_walls and interior_walls:
    print("Total estimated Cost : ",(sum(int_walls)*18+sum(ext_walls)*12),"INR")
else:
    if exterior_walls:
        print("Total estimated Cost : ",sum(ext_walls)*12,"INR")
    elif interior_walls:
         print("Total estimated Cost : ",sum(int_walls)*18,"INR")
    else:
        print("Total estimated Cost : 0.0 INR")

Practice makes a man perfect

Now, that you have successfully understood the above problems we have a similar problem statement for you enthusiasts. Try solving this question on your own.

Problem Statement : Selection of MPCS exams include a fitness test which is conducted on ground. There will be a batch of 3 trainees, appearing for running test in track for 3 rounds. You need to record their oxygen level after every round. After the trainees are finished with all rounds, calculate for each trainee his average oxygen level over the 3 rounds and select one with highest oxygen level as the most fit trainee. Thus, if more than one trainee attains the same highest average level, then all need to be selected.

Display the most fit trainee (or trainees) and the highest average oxygen level.

Note:

  1. The oxygen value entered should not be accepted if it is not in the range between 1 and 100.
  2. Moreover, if the calculated maximum average oxygen value of trainees is below 70 then declare the trainees as unfit with meaningful message as “All trainees are unfit”.
  3. Average Oxygen Values should be rounded.

Example 1: INPUT VALUES

95 // Round One (Oxygen Value of Trainee 1)
92 // Round One (Oxygen Value of Trainee 1)
95 // Round One (Oxygen Value of Trainee 1)
92 // Round Two (Oxygen Value of Trainee 1)
90 // Round Two (Oxygen Value of Trainee 1)
92 // Round Two (Oxygen Value of Trainee 1)
90 // Round Three (Oxygen Value of Trainee 1)
92 // Round Three (Oxygen Value of Trainee 1)
90 // Round Three (Oxygen Value of Trainee 1)

OUTPUT VALUES

Trainee Number : 1

Trainee Number : 3

Output must be in given format as in above example. For any wrong input final output should display “INVALID INPUT”.

TCS NQT Programming -The journey has just started

  1. Arrays and Strings are like salt and sugar of coding problems. Even though, they are the basic data structures, they can sometimes trick you!
  2. Get into algorithm mindset and feel comfortable with the basic data structures. Refresh your memory on basic concepts like initializing an array, inserting data into an array in a specific position, binary search and so on.
  3. Understand problems with higher complexity involving recursion as in Fibonacci series, string permutations and so on. Try to get into understanding the underlying concept of recursion to make coding for these questions a cup of cake for you in the coding section.
  4. In conclusion, review, review and review all the concepts! Start doing coding mock test provided on the TCS portal itself.

Conclusion

Hope you loved TCS NQT Coding questions, feel free to comment and share.

Sliding window technique, Dynammic programming are also an important topics for TCS NQT

Leave a Comment

Your email address will not be published. Required fields are marked *