You are on page 1of 14

TCS Digital Coding Questions

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

 Complete the programmerday function in the editor below. It should return a


string representing the date of the 256th day of the year given.
 programmerday has the following parameter(s):
o year: an integer 

Input Format

 A single integer denoting year y.

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

Code in Python

Question 2:

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.

countpage has the following parameter(s):

n: the number of pages in the book


p: the page number to turn to
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

Code in Python:

3) Election 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 trainee 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. If
more than one trainee attains the same highest average level, they all need to be selected.
Display the most fit trainee (or trainees) and the highest average oxygen level.
Note:
The oxygen value entered should not be accepted if it is not in the range between 1 and
100.
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.
Average Oxygen Values should be rounded.
Example 1:
INPUT VALUES
            95
            92
            95
            92
            90
            92
            90
            92
            90
OUTPUT VALUES
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
Output must be in given format as in above example. For any wrong input final output
should display “INVALID INPUT”

Question 3:
1. The program will recieve 3 English words inputs from STDIN

These three words will be read one at a time, in three separate line
The first word should be changed like all vowels should be replaced by *
The second word should be changed like all consonants should be replaced by @
The third word should be changed like all char should be converted to upper case
Then concatenate the three words and print them
Other than these concatenated word, no other characters/string should or message should
be written to STDOUT
Python Code:

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

Python Code:

6) 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.

-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.

Python Code:

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.

Python Code:

Explanation: '''The int() function converts the specified value into an integer number. We are using
the same int() method to convert the given input.int() accepts two arguments, number and base.
Base is optional and the default value is 10.In the following program we are converting to base 17'''

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.


7) Program to check if all digits of a number divide it
Python Code:

8) Python Porgam to print double sided staircase pattern

Python Code:
9) Python Program for Inverted Star Pattern

10) Python Program to calculate electric bill

Program to find the count of numbers which consists of unique digits

Program for encryption and decryption


Given a positive integer n. The task is to find the sum of product
of x and y such that ⌊n/x⌋ = y (Integer Division)

Given two numbers L and R (inclusive) find the product of primes within


this range. Print the product modulo 109+7. If there are no primes in that
range you must print 1.
Problem Statement:
A marathon is a long-distance race with an official distance of 42.195 kilometers(26 miles 385 yards), usually run as a road
race or footrace. A local marathon was organized at Bavdhan, Pune. The distance actually covered by the participants has
been recorded in an array R[ ] which is an integer array holding the values in kilometers. If there are N number of
participants who started running at a particular time, then the size of R is N. The participants should cover a distance more
than 0.0 km to get recorded in array R[ ].

Find the maximum distances covered by the 3 highest racers excluding finishers. If there are only one or two racers
excluding finishers, give their distances covered.

R[ ] will be the input float array. Write code to take the Input array R[ ], and return 3 maximum distances excluding
Finishing Distance d, d = 42.195 km

Example-1

Input Values

Enter the distances covered by racers in Marathon(Kilometers) please


(press q to terminate):

42.195

42.195

42.195

33.25

40

41.2

38.9

37.5

Output Values

Highest Distances excluding Finishers:

[41.2, 40.0, 38.9]

Python Code:

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

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
Note: Follow in input and output format as given in above example

Problem: Given arrival and departure times of all trains that reach a railway station, the task is to find the
minimum number of platforms required for the railway station so that no train waits. 
We are given two arrays which represent arrival and departure times of trains that stop
Given a string, eliminate all “b” and “ac” in the string, replace them in-place and iterate over the string once.

You might also like