You are on page 1of 18

TCS Programming Questions | TCS

Programming MCQs
Published on 07 Mar 2020
TCS Programming questions (MCQs) are discussed here with solutions. These TCS
programming MCQs were asked in the latest TCS drive. So practicing these can help you answer
a lot of questions in the TCS drive. Checkout latest TCS off campus drive details here.

TCS Programming Questions - Section Details

TCS programming concepts or programming questions section consists of 10 programming


MCQs. The time duration of this section is 20 minutes. This means you should answer a
question in a maximum of 2 minutes.

The syllabus for this section is as follows.

Programming Concepts:
Iteration, recursion, procedural vs OOP.

C Language: call by value/reference, basic and derived data types, storage class, scope and
visibility, basics of pointers, basic header files, library functions, branching and
looping, command line arguments, user-defined functions.

Algorithms:
Basic search algorithms, basic sort algorithms (tree traversal, dynamic programming, etc)

Data Structures:
Array, Stack, Queue, List (tree, hash table, etc)

TCS Programming Questions - Question Types

TCS has officially released a list of indicative question types asked in TCS Programming Mcqs
section. The following are the expected question types for this section.
 Given a code in C language/pseudo-code, Identify the functionality of the code.
 Given a code in C language/pseudo-code, identify the bug (syntactic/ semantic)
in the code.
 Conceptual Questions in programming
 Elementary algorithms based questions
 Elementary data structures based questions
 Questions based on basics of C language
 Basic Concepts behind compiling, linking, OS

TCS Programming Questions with Answers

Note: Coding using Command Line Arguments is not mandatory in TCS exam. However, you
may expect some programming MCQs based on command line Arguments. Click here to
understand Command Line Arguments better

1) Eesha was in a wonderland where she saw a treasure trove of seven items of various items (in
lakhs) and weights (in kgs) as per the table given below.

Value Weight

12 4

10 6

8 5

11 7

14 3

5 10

5 12

She wanted to bring back the maximum value of items but she was not able to carry more than
10 kgs. Using dynamic programming, what is the maximum value of the items that she could
carry back with her.
Answer: 25
2) In C language, if a function return type is not explicitly defined then it defaults to what data
type?
Answer: Int

3) Which of the following syntax is correct for command -line arguments?


a) int main (char *argv[], intargc)
b) none of the three options
c) int main () { intargv, char *argc[]; }
d) int main(int var, char *varg[])
Answer: int main (int var,char *varg[])

4) The full set of operations allowed on a stack are


a) Push, pop
b) Push, pop, remove
c) Push, pop, add, remove
d) Push,pop,add,remove,substitute
Answer: push, pop

5) Realloc() function is used to:


a) Get back the memory that was released earlier usingdree() function
b) Reallocate a file pointer when switching between files
c) Change the size of an array
d) Change the size of the dynamically allocated memory
Answer: change the size of dynamically allocated memory

6) Which of the below is NOT a data type in C language:


a) Signed int
b) Big int
c) Short int
d) Long int
Answer: Big int

7) Eesha wants to implement an image viewer application to view images in a given folder. The
application will be able to display an image and will also know what its next and previous
images are at any given point of time so that the user can so that the user can view next/previous
image by pressing right/left keys on the keyboard. Which data structure is appropriate for Esha to
use?
a) Tree
b) Queue
c) Linked list
d) Stack
Answer: Linked list

8)The pseudo code below sorts an array using bubble sort. Here A is the array and the n is the
number of elements in it. Function swap exchanges the value of 2 given value.

This function is called with A and 7 as parameter where the array initially contains the element
64, 34, 25,12, 22, 11, 9
a) 34 25 12 22 11 9 64
b) 25 12 22 11 9 34 64
c) 11 9 12 22 25 34 64
d) 12 11 9 22 25 34 64
Answer: 25 12 22 11 9 34 64

9) #define is used to
a) Define a variable
b) Define a macro
c) Define a function
d) Define a constant
Answer: Define a macro

10) What type of data structures are queues?


a) First in last out
b)First in first out
c)Last in first out
d)Last in last out
Answer: First in first out

11) Which of the following is NOT a valid storage class in C language?


a)Extern
b)Dynamic
c)Register
d)Auto
Answer: Dynamic

12) Eesha is developing a word processing software in which she wants to provide undo feature.
The software will maintain all the sequential changes and at any point of time pressing control z
will undo the latest change, what data structure should Eesha use for this?
a)Stack
b)Queue
c)Linked list
d) Array
Answer: Stack

13) #include
Main(intargc,char**argv)
{
printf(%sn,argv[--argc]);
Return 1;
}
The above program was run with the following command line parameters
Asha usha nisha easha
What was the output?
a) Nisha
b) Unable to run due to compilation error
c) No output, runtime error
d) easha
Answer: easha

TCS NQT Coding Questions & How Coding Task


Evaluated in TCS NQT
How to solve the Coding Section in TCS NQT 2020?
What is TCS NQT 2020?
“https://www.conduiraonline.com/index.php/detail/2278-tcs-nqt-2020-registration-exam-
date-exam-pattern-eligibility”-TCS NQT 2020 is the exam conducted by TCS for
recruiting freshers who are going to graduate in the year 2020. Make sure that you
understand the Eligibility criteria for the test, the syllabus and test pattern.
What is the Coding section in NQT 2020?
The coding section of the TCS NQT 2020 has one question which is usually in the form
a Case study or a Story. At the end of the Caselet, they will ask us to write a program
which takes the input in a particular format and produces the output as per the required
format.
What are the other rules for the Coding section?
You can attempt the coding task in any of the 5 languages given by TCS. These are C,
C++, Java, Python and Perl. You have a total of 30 minutes to solve this question. Here
are the most important points to know about before you attempt the coding section of
TCS NQT 2020. To know more check our blog on
“https://www.conduiraonline.com/index.php/detail/2288-programming-language-to-
answer-tcs-nqt-2020-coding-questions”.
How is the coding task evaluated?
The TCS NQT 2020 is attempted by lakhs of students. The examiners are not going to
read everyone’s code. Instead, they will use a computerized evaluation which will
automatically assign score based ONLY ON THE OUTPUT.
The main part of the coding section is “Test Cases”. Your code will be Validated against
test cases. You will be given partial marks based on how many test cases are cleared.

STEP by STEP guide to solving the coding section in TCS NQT 2020.
STEP 1: Understanding the story.
You are given 30 minutes to write a program and clear all the test cases. Of this, spend
the first five to six minutes on understanding the story given and figuring out what needs
to be calculated.
If your English is not very strong, you need to spend more time in reading and
understanding the task. Don’t jump into typing your program before you understand
what is going on.
These are the points that you need to understand from the task.
There are coins of several denominations.
Initially, there are an Even number of coins of each type.
One of the coins is lost. When you remove 1 from an even number, we get an Odd
number. So, finally we have many denominations occurring an Even number of times
but one particular denomination occurring an Odd number of times.
The first input we get is the total number of coins. Let’s call this N.
In the second line we get only N-1 values because one of the coins is missing.
The output is the denomination (value) of the missing coin.
STEP 2: Reading the inputs
Once you know what is needed, we need to think in terms of how you write the code. At
this time we don’t know how to find the answer. But we know how to take the inputs. So,
the first part of the program is to read the value of N, declare an array and read N-1
values into the array.
Even though the task keeps changing, reading a set of values in a loop is required in
many programs. You will need to practice several programs so that you won’t waste
your time in simple tasks like this in the actual exam.
STEP 3: Cracking the core logic.
The next step is to figure out how to convert this data into an answer. By the time we
reach this step in the exam, we should have about 20 minutes left.

Let’s race against the time.


Consider the example given in the question. We see that the denomination Rs.2
appears two times, Rs.1 appears two times and Rs.5 appears three times. Why is it so?
We know that originally all these are present an even number of times. But, one of the
coins got lost and that is the number which appears an odd number of times. In this
example, we can infer that originally, there were four coins with Rs. 5 but one of them
fell down. That is why we finally have three Rs.5 coins instead of four Rs.5 coins.
Here is a direct way of solving this problem. Towards the end of this article, we will see
a more efficient way of solving the same problem.
Method 1:
Task 1: Read one coin at a time in the loop. Take its value. Let’s call this a[j].
Task 2: In an inner loop, go through each coin in the list and count how many times is V
occurring. For this we first need to initialize count to zero. Whenever a[j] == a[i] is true,
we need to increment the counter.
Task 3: Once the inner loop is completed, the value of count will tell us how many times
has a[i] occurred in the array.
Task 4: We need to check if the count is Odd. We are told that only 1 denomination will
occur an odd number of times. If we find it, we can print it and exit the program.
When we divide an Odd number with 2, we get 1 as remainder. This can be obtained
using the % operator.

Step 4: Validating the code


The remaining time in the exam can be spent in verifying that the code clears all the test
cases. In case it fails, you can try giving your own inputs to find out when it is failing and
then try to correct the algorithm.
In TCS NQT 2020, you might not have a big penalty if your code is slow. So, it makes a
lot of sense for you to write working code before you worry about efficiency.
SECOND METHOD:
Once we realize that we need to find the number which is occurring an Odd number of
times, some of us can come up with an alternative method to identify it. This method is
based on the EXOR operation which is a bit-wise operation performed using the ^
symbol.
Here is the Truth table for XOR operations.
Operands Result
0^00
0^11
1^01
1^10
From the above Truth table, we can conclude that N ^ N = 0, 0 ^ N = N. Let’s say we
have 3 integers A, B and C. Here are a few interesting results from EXOR.
A^A=0
A^B^A = A^A^B = B

A^B^C^B^A^C = 0
So, if we perform the EXOR operation on a series of numbers we will notice some
interesting results.
If a particular number (say A) is occurring an Even number of times, the EXOR of all of
them together is 0. i.e. A^A^A…^A =0 when the number is occurring an Even number of
times.
If a number is occurring an Odd number of times, the EXOR of all the occurrences is
same as the number itself. So, A^A^A^….^A= A when the number is occurring an Odd
number of times.
The order in which we apply the EXOR operation doesn’t matter A^B=B^A.
Using these properties together, we can notice that when we take the EXOR of all the
inputs, any number that occurs an even number of times will give an EXOR of 0. If A is
the number that occurs an Odd number of times, the overall EXOR for all its
appearances will be equal to A. The overall result for all the other numbers will be zero.
So, finally we get A^0 which is equal to A.
Once we know this, we can go ahead and implement this in the code.
We just need to take a temporary variable to store the result. Let’s call this E and
initialize it to 0. We then need to go through a loop and perform EXOR on all the given
elements. The final value of EXOR is the answer we need.
Do I need to make my program so efficient?
While it is always good to write efficient programs you need to control your greed.
Before you worry about efficiency, you need to ensure that your program clears at least
some of the test cases. Finally, nobody reads your code – they just look at the number
of test cases. Make sure that your code clears as many test cases as possible.
However, if you know an efficient method, there is no reason for you to not use it. Go
ahead, give it best shot. This is your playground.
In which language should I write the code?
The advantage of choosing C, C++ and Java over scripting languages is that the
compiler is very strict. The probability of any mistakes being found by the compiler is
very high which means the probability of validating against the test cases is also high.
On the other hand, in scripting languages like Python or Perl the probability of finding
mistakes by compiler is not fruitful. Some of your coding mistakes might percolate till the
time you go into the compiler stage.
As we keep telling, don’t try to learn a new programming language now. Stick with a
language that you already know. Build your confidence by practicing multiple tasks
using it.
Visit this page for TCS NQT Quantitative
TCS NQT Quantitative Questions
Solve more questions on our TCS NQT Quants Dashboard
Question 1.

1. Advanced: In how many ways can we give change for rs 100  using 1 rupee and 2 rupee
coins? For example for 5 rs we can give three ways(1,1,1,1) (1,1,1,2) )(,1,2,2)

Answer: 51

Let X be the number of 1 rupee and Y be the number of 2 rupees coin


X+Y= 100
Take x = 100, Y=0
Likewise,Y=1, X=98
It will go till Y=50, X=0
Therefore there are 51 ways
Question 2
2. We are driving along a highway at a constant speed of 55 miles per hour (mph).  You
observe a car one half mile behind you. The car is moving fast and zooms past you exactly
one minute later. How fast is this car traveling (mph) if its speed is constant?
a. 80
b. 70
c. 72
d. 85
Answer: 85
3. What is the next number in the series 70,54,45,41?
a. 40
b. 35
c. 45
d. 54
Answer: 40
Question 4
4. George can do some work in 8 hours. Paul can do the same work in 10 hours while Hari
can do the same work in 12 hours. All the three of them start working at 9 AM. while George
stops work at 11 am,the remaining two complete the work,approximately when will the work
be finished?
a. 11:30 AM
b. 12 noon
c. 12.30 PM
d. 1 PM
Answer: 1 PM
Question 5
Shush and Komal can do a job together in 7 days. Shush is 7/4 times as efficient as Komal.
The same job can be done by Shush alone in
a. 49/4
b. 49/3
c. 11
d. 28/3
Answer: 11
Ratio of efficiency of Shush and Komal = 1:7/4 = 4:7
As the time taken is inversely proportional to efficiency, therefore,
if Komal takes 7x days to complete work, Asha will take 4x days.
Therefore 1/7x + 1/4x = 1/7 => (4+7)/28x = 1/7 ⇒ 28x = 11 × 7 Therefore x = {(11×7)/28} =
11/4
∴ Shush will complete the work in 4x = 4 (11/4) = 11 days.
Question 6
Advanced: a,b,c are positive numbers such that a+b+ab= 8, b+c+bc=15 and c+a+ca = 35
What is the value of a+b+c+abc?
Answer: 36
Question 7
The 260th term of the series a,b,b,c,c,c,d,d,d,d,e,e,e,e,e,f,f,f,f,f,f,….is:
a. U
b. W
c. T
d. V
Answer: W
Question 8
8. Advanced: It is possible to pair up all the numbers from 1 to 70 so that the positive
difference of the numbers in each pair is always the same. For example, one such pairing
up is (1,2), (3,4), (5,6),….(69,70). Here the common on difference is 1. What is the sum of
all such common differences.
Answer: 1680
. Advanced: It is possible to pair up all the numbers from 1 to 70 so that the positive
difference of the numbers in each pair is always the same. For example, one such pairing
up is (1,2), (3,4), (5,6),….(69,70). Here the common on difference is 1. What is the sum of
all such common differences.
Answer: 1680
Question 9
9. Advanced: A  regular polygon with 12  sides (dodecagon) is inscribed in a square
of area 24 square units as shown in the figure where four of the vertices are mid
points of the sides of the square . The area of the dodecagon in square units is.
Answer: 19

Question 10
Advanced:
In how many ways can we give change for 100 using 1 rupee and 2 rupee coins? For
example for 5 rs, we can give in three ways : (1,1,1,1,1) (1,1,1,2) (1,2,2)
Answer: 51
Question 11
Advanced: In the figure shown, a triangle is divided into nine strpes of equal height each
parallel to the same side of the triangle. The shaped stripes have a total area of 135 square
units. What is the area of the triangle in square units.
Answer: 243
Question 12
In the IT department of backrub, the administrator password is changed every month. The
team of administrator, spread across the globe, receive an 8 digits number via email. This
number is to be prefixed with a single digit number and suffixed with a single digit number to
get the actual password. The password is divisible by 11 and 8. If the team received
54218345 this month. Then which of the following pairs give valid prefix and suffix
respectively?
a. 3,7
b. 1,6
c. 2,4
d. 4,2
Answer: 1,6
Question 13
13. In the diagram below, the areas of the triangles are as follows: A1=1024, A2=1016,
A3=1057. What is the area of A4?
a. 1032
b. 1036
c. 1020
d. 1065
Answer: 1065
Question 14
14. The people of the land of unsymmetrix to ensure that there is very little symmetry in life.
Even their unit of length (no one knows what it is) is called as unsym. It is their pride that the
front wheel and the real wheels of their bikes are of different sizes but are made so that they
will not slip on the road . In a certain model of bike the radius of the front wheel is 28
unsyms and that of the back wheels is 14 unsyms after driving a certain distance if front
wheel had revolution 54 times how many revolution would the back wheel have undergone?
a. 136
b. 122
c. 108
d. 94
Answer: 108
Question 15
15. Rs. 3000 is distributed among A, B and C such that A gets 2/3rd of what B and C
together get and C gets ½ of what A and B together get. Find C’s share.
a. 1500
b. 1000
c. 1200
d. 1800
Answer: 1000
Question 16
16.
Given that 1 < a< b< c< d, Which of the following is largest ?
In this question , x^y stands for x raised to the power of y. For example , 2^3=8 and 4^1.5=8
exp(x) is e (approx 2.7183) raised to the power x. Thus exp(2.303) is approximately 10.

1. exp (a^d)/exp (b^c)


2. exp (c^d)/ exp(a^b)
3. exp (b^d)/exp(a^c)
4. exp(b^c)/exp(a^d)

Answer: exp(c^d)/exp(a^b)
Question 17
17.  32 times of a two digit number is 23 times the number obtained by reversing its digit.
The sum of its digit is 15 Find the number:
a. 96
b. 69
c. 87
d. Insufficient information
Answer: 69
Question 18
18. Let N be the greatest number that will divide 148, 246 and 623 leaving remainders 4, 6
and 11 respectively. What is the remainder if N is divided by 7?
a. 0
b. 1
c. 5
d. 6
Answer: 5
Question 19
19. A store is selling a jacket on sale at 30% off the marked price. A matching pair of pants
is on sale at 40% off the marked price. If the marked price of the pants is Rs. 8500 less than
the marked price of the jacket and the total sale price of both items is Rs. 23500, then what
is the marked price of the jacket?
a. 21700
b. 21800
c. 22000
d. 22100
Answer: 22000
Question 20
Initially, when Sona and Tina left for a shopping expedition , Sona had three times the
money than Tina had. They bought things amounting to Rs. 480 altogether, out of which
Tina’s share was 65%. At the end of shopping, Sona was left with 4 times the amount that
Tina had. What was the amount with Tina at the beginning?
a. 1080
b. 1248
c. 768
d. 936
Answer: 1080
Question 21
A semcircle is drawn on one of the sides of the square with the side of the square as the
diameter of the circle. It the length of the side of the square is 2 What is the radius of the
smallest circle that can contain this figure?

Write your answer in fraction


Answer: 17/8
Question 22
Bhaskar arid Shalcuntala challenge each other in math and are at loggerheads always. At
the end of a milestone in their protect, the team had a dinner and were seated In a circular
table. If there were 16 people for dinner, what are the odds against the event that Bhaskar
and Shakuntala will sit together(Give the answer as a:b)
Answer: 13:2
Question 23
The expression 3(x2) - mx+10 leaves a remainder of -2 when divided by x-3. What’s the
value of m?
Answer: 13
Question 24
12 Litres of water is poured Into an aquarium of dimensions 50cm length. 30cm breadth and
40cm height By what height (In cm) will the water rise?
a. 10
b. 8
c. 12
d. 20
Answer: 8
Question 25
Two finals are scheduled - The Wimbledon match and the World Cup Cricket at the same
time. Anu wants to watch the Wimbledon finals and her brother Vinu wants to watch WCC
final. They decide to roll a tetrahedral die twice. The tetrahedral Is numbered 1,2,3,4 on its
four sides and ll numbers are equaly likely to appear. Anu rolls fist and then Vinu rolls. If the
number on the first roll Is strictly greater than the number on the second roll. Anu wins and
gets to watch Wimbledon. What Is the probability that Anu will get to watch Wimbledon?
a. 7/16
b. 9/1
c. 3/4
d. 1/2
Answer: 3/4
Question 26
An electrical circuit has:

 . A power source
 . A resistor R and
 . Three paraIlelIy connected resistors each of value 3R.

All these connected In series. If the current flowing through the circuit is five amperes, what
will be its value, if R Is doubled and each of 3R is halved?
Answer: 4 amps
Question 27
Ms Thkonapr*ya wants to decorate her abode’s frontage with a triangular lawn. The two
sides of this lawn are of five and sIx meters, subtending an angle of 30 degrees. If the Lawn
maintainer charges Rs.10 per square meter. how much would Trlkonaprlya pay to him for
the entire lawn? You answer should contain only the numeric value.
Answer: 75
Question 28
8haskar wanted to send some documents to Shakuntala He had her address without the 6-
digit pin code. He didn’t want to risk sending documents without pin code. So. he called
Shakuntala. She did not give the pin code directly, she said. The first four digits are 1910 in
hexadecimal and the last four digits are 3177 in octal”. Bhaskar could courier the
documents now. What is her pin code?
Answer: 641683
Question 29
If it takes 10 3D printers 10 minutes to print 10 models, how long will It take 100 printers to
print 100 models?
Fill the correct answer in minutes.
Answer: 10minutes
Question 30
Eighty cricket balls have been packed equally Into two bags A and B. 20 of these bails have
been signed by Kapii Dcv - some of the signed balls are in bag A and the rest in bag B. One
bag ¡s selected and a ball is randomly picked from that Given that the bal is signed, the
pobabllity that It ¡s from Bag B is computed to be 44. If bag A is twice more likely to be
selected than Bag B. how many of the signed bails are in Bag B?
Answer: 16

You might also like