TCS Ninja Toppers Test Coding Questions

Latest TCS Ninja Toppers Test Coding Questions 2022

The questions asked in this round will be different from the types of questions asked in TCS Ninja Coding Round and will also be with higher difficulty level.

You will be given 2 coding questions with high difficulty and you will have to solve those in definite time limit of 60 mins.  If you are be able to clear the test then you will get the opportunity to go for TCS Digital Interview.

This test is only for the top 10% performers of TCS NQT (Ninja Profile) candidates.

Click on the button given below to know about the exact syllabus of TCS Ninja Toppers Test.

TCS ninja topper test coding questions

Detailed TCS Ninja Toppers Test Syllabus

TCS Toppers Test
Information
Total Question2
Total Alloted60 min
DifficultyHigh
Negative MarkingNo

TCS Ninja Toppers Test: Language

Languages that you can choose for test –

  1. C
  2. C#
  3. C++
  4. Erlang
  5. go
  6. Haskel
  7. Java
  8. Java 7
  9. Kotlin
  10. Lua
  11. Perl
  12. Python
  13. Python3
  14. Ruby
  15. Scala

TCS Ninja Toppers Test Coding Questions

Question 1

Problem Description -: Given an array Arr[ ] of N integers and a positive integer K. The task is to cyclically rotate the array clockwise by K.

Note : Keep the first of the array unaltered.

 

Example 1:

  • 5  —Value of N
  • {10, 20, 30, 40, 50}  —Element of Arr[ ]
  • 2  —–Value of K

Output :

40 50 10 20 30

Example 2:

  • 4  —Value of N
  • {10, 20, 30, 40}  —Element of Arr[]
  • 1  —–Value of K

Output :

40 10 20 30

 

Question 2

Problem Description -:  Given two non-negative integers n1 and n2, where n1

For example:

Suppose n1=11 and n2=15.

There is the number 11, which has repeated digits, but 12, 13, 14 and 15 have no repeated digits. So, the output is 4.

Example1:

Input:

  • 11 — Vlaue of n1
  • 15 — value of n2

Output:

  • 4

Example 2:

Input:

  • 101 — value of n1
  • 200 — value of n2

Output:

  • 72

Question 3

Problem Statement-:

Identify the logic behind the series

6 28 66 120 190 276….

The numbers in the series should be used to create a Pyramid. The base of the Pyramid will be the widest and will start converging towards the top where there will only be one element. Each successive layer will have one number less than that on the layer below it. The width of the Pyramid is specified by an input parameter N. In other words there will be N numbers on the bottom layer of the pyramid.

The Pyramid construction rules are as follows

  1. First number in the series should be at the top of the Pyramid
  2. Last N number of the series should be on the bottom-most layer of the Pyramid, with Nthnumber being the right-most number of this layer.
  3. Numbers less than 5-digits must be padded with zeroes to maintain the sanctity of a Pyramid when printed. Have a look at the examples below to get a pictorial understanding of what this rule actually means.

Example

If input is 2, output will be

  • 00006
  • 00028 00066

If input is 3, output will be

  • 00006
  • 00028 00066
  • 00120 00190 00276

Formal input and output specifications are stated below

Input Format:

  • First line of input will contain number N that corresponds to the width of the bottom-most layer of the Pyramid

Output Format:

  • The Pyramid constructed out of numbers in the series as per stated construction rules

Constraints:

  • 0 < N <= 14

 

Question 4

Problem Statement-:  There are two banks – Bank A and Bank B. Their interest rates vary. You have received offers from both banks in terms of the annual rate of interest, tenure, and variations of the rate of interest over the entire tenure.You have to choose the offer which costs you least interest and reject the other. Do the computation and make a wise choice.

The loan repayment happens at a monthly frequency and Equated Monthly Installment (EMI) is calculated using the formula given below :

EMI = loanAmount * monthlyInterestRate / ( 1 – 1 / (1 + monthlyInterestRate)^(numberOfYears * 12))

 

Constraints:

  • 1 <= P <= 1000000
  • 1 <=T <= 50
  • 1<= N1 <= 30
  • 1<= N2 <= 30

 

Input Format:

  • First line: P principal (Loan Amount)
  • Second line: T Total Tenure (in years).
  • Third Line: N1 is the number of slabs of interest rates for a given period by Bank A. First slab starts from the first year and the second slab starts from the end of the first slab and so on.
  • Next N1 line will contain the period  and their interest rate respectively.
  • After N1 lines we will receive N2 viz. the number of slabs offered by the second bank.
  • Next N2 lines are the number of slabs of interest rates for a given period by Bank B. The first slab starts from the first year and the second slab starts from the end of the first slab and so on.
  • The period and rate will be delimited by single white space.

 

Output Format: Your decision either Bank A or Bank B.

 

Explanation:

  • Example 1
    • Input
    • 10000
    • 20
    • 3
    • 5 9.5
    • 10 9.6
    • 5 8.5
    • 3
    • 10 6.9
    • 5 8.5
    • 5 7.9
  • Output: Bank B
  • Example 2
    • Input
    • 500000
    • 26
    • 3
    • 13  9.5
    • 3  6.9
    • 10  5.6
    • 3
    • 14  8.5
    • 6  7.4
    • 6  9.6
  • Output: Bank A

Question 5

Problem Description -:  In this 3 Palindrome, Given an input string word, split the string into exactly 3 palindromic substrings. Working from left to right, choose the smallest split for the first substring that still allows the remaining word to be split into 2 palindromes.

Similarly, choose the smallest second palindromic substring that leaves a third palindromic substring.

If there is no way to split the word into exactly three palindromic substrings, print “Impossible” (without quotes). Every character of the string needs to be consumed.

Cases not allowed –

  • After finding 3 palindromes using above instructions, if any character of the original string remains unconsumed.
  • No character may be shared in forming 3 palindromes.

Constraints

  • 1 <= the length of input sting <= 1000

Input

  • First line contains the input string consisting of characters between [a-z].

Output

  • Print 3 substrings one on each line.

Time Limit

1

Examples

Example 1

Input

nayannamantenet

Output

nayan

naman

tenet

Explanation

  • The original string can be split into 3 palindromes as mentioned in the output.
  • However, if the input was nayanamantenet, then the answer would be “Impossible”.

Example 2

Input

aaaaa

Output

a

a

aaa

Explanation

  • The other ways to split the given string into 3 palindromes are as follows –
  • [a, aaa, a], [aaa, a, a], [aa, aa, a], etc.
  • Since we want to minimize the length of the first palindromic substring using left to right processing, the correct way to split is [a, a, aaa].

Example 3

Input

aaaabaaaa

Output

a

aaabaaa

a

Explanation

  • The other ways to split the given string into 3 palindromes are as follows –
  • [aaaa, b, aaaa], [aa, aabaa, aa], etc.
  • Since we want to minimize the length of the first palindromic substring using left to right processing, the correct way to split is [a, aaabaaa, a].

Question 6

Roco is an island near Africa which is very prone to forest fire. Forest fire is such that it destroys the complete forest. Not a single tree is left.This island has been cursed by God , and the curse is that whenever a tree catches fire, it passes the fire to all its adjacent tree in all 8 directions,North, South, East, West, North-East, North-West, South-East, and South-West.And it is given that the fire is spreading every minute in the given manner, i.e every tree is passing fire to its adjacent tree.Suppose that the forest layout is as follows where T denotes tree and W denotes water.

Your task is that given the location of the first tree that catches fire, determine how long would it take for the entire forest to be on fire. You may assume that the lay out of the forest is such that the whole forest will catch fire for sure and that there will be at least one tree in the forest

Input Format:

  • First line contains two integers, M, N, space separated, giving the size of the forest in terms of the number of rows and columns respectively.
  • The next line contains two integers X,Y, space separated, giving the coordinates of the first tree that catches the fire.
  • The next M lines, where ith line containing N characters each of which is either T or W, giving the position of the Tree and Water in the  ith row of the forest.

Output Format:

Single integer indicating the number of minutes taken for the entire forest to catch fire

Constrains:

  • 3 ≤ M ≤ 20
  • 3 ≤ N ≤ 20

Sample Input 1:

3 3
W T T
T W W
W T T
Sample Output 1:

5

Explanation:
In the second minute,tree at (1,2) catches fire,in the third minute,the tree at (2,1) catches fire,fourth minute tree at (3,2) catches fire and in the fifth minute the last tree at (3,3) catches fire.
Sample Input 2:
6 6
1 6
W T T T T T
T W W W W W
W T T T T T
W W W W W T
T T T T T T
T W W W W W

Sample Output 2:

16

For more coding questions of similar types, visit this link below:-

Coding Questions for Toppers Test: Video

FAQs

What will be the difficulty level of Toppers test?

The difficulty level of Toppers Test is high. The difficulty level will be as same of TCS Digital and TCS Digital is considered as the most tough exam held by TCS.

Will there be negative marking in the exam?

As per the current information, No there will be no negative marking in the exam. But yes, the difficulty level will be high so you need to prepare well for this round.