TCS Digital Coding Questions
TCS Digital Coding Questions
Problem Statement-:
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.
Example
• 00006
• 00028 00066
• 00006
• 00028 00066
• 00120 00190 00276
• 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 2
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 :
Constraints:
Input Format:
Explanation:
• Example 1
o Input
o 10000
o 20
o 3
o 5 9.5
o 10 9.6
o 5 8.5
o 3
o 10 6.9
o 5 8.5
o 5 7.9
• Output: Bank B
• Example 2
o Input
o 500000
o 26
o 3
o 13 9.5
o 3 6.9
o 10 5.6
o 3
o 14 8.5
o 6 7.4
o 6 9.6
• Output: Bank A
Question 3
Problem Statement-:One person hands over the list of digits to Mr. String, But Mr.
String understands only strings. Within strings also he understands only vowels. Mr.
String needs your help to find the total number of pairs which add up to a certain digit D.
• Take all digits and convert them into their textual representation
• Next, sum up the number of vowels i.e. {a, e, i, o, u} from all textual representation
• This sum is digit D
Now, once digit D is known find out all unordered pairs of numbers in input whose sum
is equal to D. Refer example section for better understanding.
Constraints
Input
Output
Time Limit
Examples
Example 1
Input
12345
Output
one
Explanation
Now from the given list of numbers {1,2,3,4,5} -> find all pairs that sum up to 9.
Upon processing this we know that only a single unordered pair {4, 5} sum up to 9.
Hence the answer is 1. However, output specification requires you to print textual
representation of number 1 which is one. Hence output is one.
Note: – Pairs {4, 5} or {5, 4} both sum up to 9. But since we are asking to count only
unordered pairs, the number of unordered pairs in this combination is only one.
Example 2
Input
3
742
Output
zero
Explanation
Question 4
Problem Statement:- Jaya invented a Time Machine and wants to test it by time-
traveling to visit Russia on the Day of Programmer (the 256thday of the year) during a
year in the inclusive range from 1700 to 2700. From 1700 to 1917 , Russia’s official
calendar was the Julian Calendar since 1919 they used the Gregorian calendar system.
The transition from the Julian to Gregorian calendar system occurred in 1918 , when the
next day after 31 January was February 14 . This means that in 1918, February 14 was
the 32nd day of the year in Russia. In both calendar systems, February is the only month
with a variable amount of days; it has 29 days during a leap year, and 28 days during all
other years. In the Julian calendar, leap years are divisible by 4 ; in the Gregorian
calendar, leap years are either of the following:
• Divisible by 400
• Divisible by 4 and not divisible by 100
Given a year, y, find the date of the 256th day of that year according to the official
Russian calendar during that year. Then print it in the format dd.mm.yyyy, where dd is the
two-digit day, mm is the two-digit month, and yyyy is y.
For example, the given year is 1984.1984 is divisible by 4, so it is a leap year. The 256
day of a leap year after 1918 is September 12, so the answer is 12.9.1984.
Function Description
Input Format
Output Format
• Print the full date of programmerday during year y in the format dd.mm.yyyy,
where dd is the two-digit day, mm is the two-digit month, and yyyy is y.
Sample Input
2017
Sample Output
13.09.2017
Question 5
Problem Statement:- Hobo’s Drawing teacher asks his class to open their books to a
page number. Hobo can either start turning pages from the front of the book or from the
back of the book. He always turns pages one at a time. When she opens the book, page
1 is always on the right side: When he flips page 1, he sees pages 2 and 3. Each page
except the last page will always be printed on both sides. The last page may only be
printed on the front, given the length of the book. If the book is n pages long, and he
wants to turn to page p, what is the minimum number of pages he will turn? He can
start at the beginning or the end of the book. Given n and p, find and print the minimum
number of pages Hobo must turn in order to arrive at page p
Function Description
Complete the countpage function in the editor below. It should return the minimum
number of pages Hobo must turn.
Input Format
• The first line contains an integer n, the number of pages in the book.
• The second line contains an integer, p, the page that Hobo’s teacher wants her to
turn to.
Output Format
• Print an integer denoting the minimum number of pages Hobo must turn to get to
page p
Sample Input
6
2
Sample Output
Question 6
Problem Statement:- Dr. Vishnu is opening a new world class hospital in a small town
designed to be the first preference of the patients in the city. Hospital has N rooms of
two types – with TV and without TV, with daily rates of R1 and R2 respectively.
However, from his experience Dr. Vishnu knows that the number of patients is not
constant throughout the year, instead it follows a pattern. The number of patients on
any given day of the year is given by the following formula –
• (6-M)^2 + |D-15| ,
where M is the number of month (1 for jan, 2 for feb …12 for dec) and D is the date
(1,2…31).
All patients prefer without TV rooms as they are cheaper, but will opt for with TV rooms
only if without TV rooms are not available. Hospital has a revenue target for the first
year of operation. Given this target and the values of N, R1 and R2 you need to identify
the number of TVs the hospital should buy so that it meets the revenue target. Assume
the Hospital opens on 1st Jan and year is a non-leap year.
Constraints
Hospital opens on 1st Jan in an ordinary year
Input Format
• First line provides an integer N that denotes the number of rooms in the hospital
• Second line provides two space-delimited integers that denote the rates of
rooms with TV (R1) and without TV (R2) respectively
• Third line provides the revenue target
Output
• Minimum number of TVs the hospital needs to buy to meet its revenue target. If
it cannot achieve its target, print the total number of rooms in the hospital.
Test Case
Example-1 :
Input
20
1500 1000
7000000
Output
14
Explanation
Using the formula, the number of patients on 1st Jan will be 39, on 2nd Jan will be 38
and so on. Considering there are only twenty rooms and rates of both type of rooms are
1500 and 1000 respectively, we will need 14 TV sets to get revenue of 7119500. With 13
TV sets Total revenue will be less than 7000000
Example-2 :
Input
10
1000 1500
10000000
Output
10
Explanation
In the above example, the target will not be achieved, even by equipping all the rooms
with TV. Hence, the answer is 10 i.e. total number of rooms in the hospital.
Question 7
Problem Statement:- You will be given an array of integers and a target value.
Determine the number of pairs of array elements that have a difference equal to a target
value.
For example, given an array of [1, 2, 3, 4] and a target value of 1, we have three values
meeting the condition: 2-1 = 1, 3-2 = 1, and 4-3 = 1.
Function Description
Write a function pairs. It must return an integer representing the number of element
pairs having the required difference.
Input Format
• The first line contains two space-separated integers n and k, the size of arr and
the target value.
• The second line contains n space-separated integers of the array arr.
Sample Input
52
15342
Sample Output
Question 8
Problem Statement:- A jail has a number of prisoners and a number of treats to pass
out to them. Their jailer decides the fairest way to divide the treats is to seat the
prisoners around a circular table in sequentially numbered chairs. A chair number will
be drawn from a hat. Beginning with the prisoner in that chair, one candy will be handed
to each prisoner sequentially around the table until all have been distributed.
The jailer is playing a little joke, though. The last piece of candy looks like all the others,
but it tastes awful. Determine the chair number occupied by the prisoner who will
receive that candy.
For example, there are 4 prisoners and 6 pieces of candy. The prisoners arrange
themselves in seats numbered 1 to 4 . Let’s suppose two are drawn from the hat.
Prisoners receive candy at positions 2,3,4,1,2,3. The prisoner to be warned sits in chair
number 3
Function Description
Input Format
• The first line contains an integer t, denoting the number of test cases.
• The next t lines each contain 3 space-separated integers:
o – : n the number of prisoners
o – : m the number of sweets
o – : s the chair number to start passing out treats at
Output Format
• For each test case, print the chair number of the prisoner who receives the awful
treat on a new line.
Sample Input
2
521
522
Sample Output
2
3