# TCS NQT Previous Years Coding Questions | Oct-8-2020

TCS Coding section mainly focuses on candidates basic abilitya and logical thinking  to write a simple and clean code. Therefore they don’t ask very tough questions, mostly the question level is moderate and if you have a good grip on basic programming concepts you should be able to solve them very easily.

### TCS NQT Previous Years Coding Questions For example, look at this question (TCS Ninja 2019 & TCS NQT 2020)

Example:Consider the below series:

1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …

This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and all the even terms are the prime numbers in ascending order.

Write a program to find the Nth term in this series.

How to solve this Question

Just read the question once again, if you carefully observe, to solve the above problem you should know how to calculate the prime number and then Fibonacci numbers and even odd positions. So if you know these mentioned basic concepts then you can easily write the code for the above question.

So, it highly recommended learning the basics thoroughly before solving the previous year questions.

### Here is a list of all the core concepts essential for TCS coding section

1.Program to find if the given number is even & odd

2 Program to check if the given number is prime

3.Program to check if the given number is a palindrome

4.Program to check if the given number is perfect.

5.Program to check if the given number is Armstrong

6.Program to check if the given number is Strong

7.Program to count the digits in the given number

8.Program to find the factorial of the given number

9.Program to print Fibonacci series

10.Program to swap two numbers

11.Program to print HelloWorld without a semicolon

12.Program to find the largest of two numbers without conditional

13.Program to find the area of a triangle when the sides are given

14.Program to find the volume of a sphere

15.Program to find if the given year is leap year

16.Program to convert decimal to binary and vice versa

17.Program to find the LCM of two numbers

18.Program to find the GCD of two numbers

19.Program to display different patterns

20.Program to remove duplicate numbers in an Array

21.Program to find the highest value from an given Integers

Assuming that you have mastered the fundamentals now the next important thing is to solve all the previous year tcs nqt questions. To make your learning process easy we are listing them here for your reference. Also do note that remembering the code doest make any sense because you may not see the exact same question. It has been observed that TCS generally make some minor modifications to the below-mentioned questions every year. So your focus should be learning the approach of solving the question rather than blind mug up.

#### Question 1

Given a series whose even term represents a geometric series with common ratio 3 and the odd term is another geometric series with common ratio 4

Write a program to print the Nth number in the series. Here N is sent as a command-line argument.

For example 1, 1, 3, 4, 9,16, 27 ….

Approach
Geometric series is of format a, ar ar2, ar3…. Here a is the first number and r is the common ratio. From the problem statement, we know that a is 1 in both even and odd positions and common ratios are 3 and 4 respectively.

The approach to solve this is when n is given, we find whether n is even or odd, based on that we can divide it by 2 since its a mix of two series and then find the appropriate number. Also, it’s important to note that when n is even division by 2 is an integer but when divided by the odd number we get a decimal value so we can round it off to higher-order i.e 3.5 is converted to 4

# Mixed Geometric series question

-def checkEven(num):

if num % 2 ==0:

return 1

else:

return 0

def geometricSeries(a,r,pos):

return int(a*(r**(pos-1)))

num = int(input())

if checkEven(num):

print(geometricSeries(1,4,num//2))

else:

print(geometricSeries(1,3,num//2+1))

Question 2
Write a program to print reverse substring of first four letters of the given input

eg input: Indianocean, output: idni

Approach

This could be solved by two steps, one to find the substring of the given word then reversing the substring

#### Code Solution

str = input(“Enter a string: “)

str_new = str[0:4]

print(str_new[::-1])

#### Question 3

Write a python program to add 10 subsequent prime numbers from the given prime number.
Approach
The easy way would be writing a loop with a counter for 10 and iterating to check if each number is prime or not if prime then we will add it to our temp variable.

### Solution

def prime(num):

for i in range(2,num):

if num % i == 0:

return 0

return 1

num = int(input(“Enter a prime number:”))

counter = 0

sum = 0

while(counter!=10):

num = num + 1

if prime(num):

counter = counter + 1 sum = sum + num #

print(nusm, sum) print(sum)