TCS NQT 2020 Coding Questions

 TCS NQT 2020 Coding Questions

 
All these coding questions had appeared in TCS NQT 2020 Exam which was held in the month of August 2019. 

 
1. One programming language has the following keywords that cannot be used as identifiers:

break, case, continue, default, defer, else, for, func, goto, if, map, range, return, struct, type, var

Write a program to find if the given word is a keyword or not
 
Test cases
Case 1
    Input – defer
    Expected Output – defer is a keyword

Case 2
    Input – While
    Expected Output – while is not a keyword



 
Q2. Given a maximum of four digit to the base 17 (10 – A, 11 – B, 12 – C, 13 – D … 16 – G} as input, output its decimal value.
 
Test Cases
Case 1

    Input – 1A
    Expected Output – 27

Case 2
    Input – 23GF
    Expected Output – 10980




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

    Input: 4567
    Expected Output: 2

Explanation : Odd positions are 4 and 6 as they are pos: 1 and pos: 3, both have sum 10. Similarly, 5 and 7 are at even positions pos: 2 and pos: 4 with sum 12. Thus, difference is 12 – 10 = 2
 
Case 2
    Input: 5476
    Expected Output: 2

Case 3
    Input: 9834698765123
    Expected Output: 1




Q4. Our hoary culture had several great persons since time immemorial and king vikramaditya’s nava ratnas (nine gems) belongs to this ilk. They are named in the following shloka:

Among these, Varahamihira was an astrologer of eminence and his book Brihat Jataak is recokened as the ultimate authority in astrology.

He was once talking with Amarasimha,another gem among the nava ratnas and the author of Sanskrit thesaurus, Amarakosha.

Amarasimha wanted to know the final position of a person, who starts from the origin 0 0 and travels per following scheme.

Scheme
  • He first turns and travels 10 units of distance
  • His second turn is upward for 20 units
  • Third turn is to the left for 30 units
  • Fourth turn is the downward for 40 units
  • Fifth turn is to the right(again) for 50 units

… And thus he travels, every time increasing the travel distance by 10 units.

 
Test Cases
Case 1 
    Input : 3
    Expected Output :-20 20
 
Case 2
     Input: 4
    Expected Output: -20 -20
 
Case 3
    Input : 5
    Expected Output : 30 -20
 
Case 4
    Input : 7
    Expected Output : 90 -20

 

Q5. Write a code to check whether no is prime or not. Condition use function check() to find whether entered no is positive or negative ,if negative then enter the no, And if yes pas no as a parameter to prime() and check whether no is prime or not?

 

Q6. Program to check if a year is Leap Year or not 

 

Comments