In this article, we will be discussing some of the TCS Ninja Coding Questions and answers asked in the previous Recruitment Processes.
When it comes to cracking the TCS Ninja, Coding Questions are the one important section to master. The TCS Ninja Coding Questions section will be available under the Programming part (Part B).
To know more about the TCS Ninja Recruitment Process, Click here.
The TCS Ninja Coding Questions have been of the following pattern given below
To know more about the TCS Ninja Syllabus, Click here.
Given below are questions from the TCS Ninja Coding Questions (Hands-on Coding section) asked in the TCS Ninja Recruitment Processes.
Given a maximum of four digits to the base 17(10 -> A, 11 -> B, 12 -> C, 16 -> G) as input, output its decimal value.
Input:
23GF
TCS Ninja Coding Questions #1 – Solution and Output
@@coding::3@@
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 the Sanskrit thesaurus, Amarakosha. Amarasimha wanted to know the final position of a person, who starts from the origin 0 0 and travels per the following scheme.
… And thus he travels, every time increasing the travel distance by 10 units.
Constraints:
2<=n<=1000
Input:
3
TCS Ninja Coding Questions #2 – Solution and Output
@@coding::4@@
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
Input #1:
defer
Output:
defer is a keyword
Input #2:
While
TCS Ninja Coding Questions #3 – Solution and Output
@@coding::5@@
There is a jar full of candies for sale at a mall counter. The jar has the capacity N, that is JAR can contain maximum N Candies when a JAR is full. At any point in time, JAR can have an M number of candies where M<=N. Candies are served to the customers. JAR is never remaining empty as when the last K candidates are left, JAR is refilled with new candidates in such a way that JAR gets full.
Write the code to implement the above scenario. Display JAR at the counter with the available number of candies.
Input should be the number of candies one customer orders at a point in time. Update the JAR after every purchase and display JAR at the counter. The output should give the number of candies sold and the updated number of candies in the JAR. If the input is more than the number of candies in JAR, return “INVALID INPUTâ€.
Given,
N=10, Where N is the number of candies available, K<=5, Where K is the number of minimum candies that must be inside JAR ever.
Example1: (N=10,K=<5)
Input #1:
3
Output :
Number of Candies Sold: 3
Number of Candies available:7
Input #2:
4
@@coding::6@@
The selection of MPCS exams includes a fitness test which is conducted on the ground. There will be a batch of 3 trainees, appearing for a running test on track for 3 rounds.
You need to record their oxygen level after every round. After trainees are finished with all rounds, calculate for each trainee his average oxygen level over the 3 rounds and select the one with the highest average oxygen level as the fittest trainee. If more than one trainee attains the same highest average level, they all need to be selected. Display the fittest trainee(or trainers) 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. If the calculated maximum average oxygen value of the trainees is below 70 then declare the trainees as unfit with a meaningful message as “All trainees are unfitâ€
3. Average oxygen values should be rounded
Example 1:
Input #1:
95
92
95
92
90
92
90
92
90
Output:
Trainee Number: 1
Trainee Number: 3
Note: Input should be 9 integer values representing oxygen levels entered in order as
Round 1:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Round 2:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Round 3:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Oxygen must be in the given format as in the above example. For any wrong input, the final output should display “INVALID INPUTâ€
Input #2:
91
92
45
92
80
90
90
92
90
TCS Ninja Coding Questions #5 – Solution and Output
@@coding::7@@
Given a pair of positive integers m and n (m < n; 0 < m < 999; 1 < n < = 999), write a program to smartly affix zeroes, while printing the numbers from m to n.
Example-1
Input
5 10
Expected output
05 06 07 08 09 10
Example-2
Input
9 100
Expected output
009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100
Example-3
Input
1 9
TCS Ninja Coding Questions #6 – Solution and Output
@@coding::8@@
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
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
TCS Ninja Coding Questions #7 – Solution and Output
@@coding::9@@
Problem statement:
It was one of the places, where people need to get their provisions only through fair price (“rationâ€) shops. As the elder had domestic and official work to attend to, their wards were asked to buy the items from these shops. Needless to say, there was a long queue of boys and girls. To minimize the tedium of standing in the serpentine queue, the kids were given mints. I went to the last boy in the queue and asked him how many mints he has. He said that the number of mints he has is one less than the sum of all the mints of kids standing before him in the queue. So I went to the penultimate kid to know how many minutes she has.
She said that if I add all the mints of kids before her and subtract one from it, the result equals the mints she has. It seemed to be a uniform response from everyone. So, I went to the boy at the head of the queue consoling myself that he would not give the same response as others. He said, “I have four mintsâ€.
Given the number of the first kid’s mints (n) and the length (len) of the queue as input, write a program to display the total number of mints with all the kids.
constraints:
2<n<10
1<len<20
Input#1:
4 2
Output:
7
Input#2:
14 4
TCS Ninja Coding Questions #8 – Solution and Output
@@coding::10@@
TCS Ninja Numerical Ability Questions
TCS Ninja Verbal Ability Questions
TCS Ninja Reasoning Ability Questions
TCS Ninja Programming Logic Questions
TCS Ninja Questions | TCS Ninja Placement Papers
TCS Ninja Interview Questions | Technical and HR Questions