0% found this document useful (0 votes)
5 views

Array_strings_TCS Questions

The document provides a comprehensive list of important questions and coding problems for TCS NQT Batch 2025, covering topics such as basic math, arrays, strings, sorting techniques, and problem statements involving algorithms. It includes links to solutions and live classes, along with specific coding challenges that require problem-solving skills. Additionally, it offers examples and expected outputs for various coding scenarios to aid in preparation.

Uploaded by

anuragkakade0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Array_strings_TCS Questions

The document provides a comprehensive list of important questions and coding problems for TCS NQT Batch 2025, covering topics such as basic math, arrays, strings, sorting techniques, and problem statements involving algorithms. It includes links to solutions and live classes, along with specific coding challenges that require problem-solving skills. Additionally, it offers examples and expected outputs for various coding scenarios to aid in preparation.

Uploaded by

anuragkakade0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

For solutions and live classes, you can join

TCS Updated Live Crash Course:


https://bfwhv.courses.store/634755

➡️Use code: TCS25


(Last 10 Seats Left)
Important Questions TCS NQT- Batch 2025
Basic Maths Questions
Q1. Count digits of a number. Link
Q2. Find whether given number is Palindrome or not. Link
Q3. Factorial of a number. Link
Q4. Check whether given number is prime or not. Link
Q5. print all Prime factors of given number. Link
Q6. GCD of two numbers. Link
Q7. Check whether given number is Armstrong number or not. Link
Q8. Fibonacci series. Link
Q9. Check if given number is expressed as sum of 2 prime numbers. Link
Q10. Find Sum of AP Series. Link
Q11. Program to find sum of GP Series. Link
Q12. Check Leap Year or not. Link
Q13. Maximum and Minimum digit in a number. Link
Q14. Check if a number is perfect number. Link
Q15. LCM of two numbers. Link
Q16. Convert Binary to decimal and decimal to binary number system. Link Link

Array Questions
Q1. Largest and smallest element in an array. Link
Q2. Second largest and second smallest element in an array. Link
Q3. Check if the array is sorted. Link
Q3. Left rotate an array by K places. Link
Q4. Right rotate an array by K places.
Q5. Reverse the array. Link
Q6. Find missing number in an array. Link
Q7. Find number that appears one and other appears twice. Link
Q8. Move all zero to end of the array. Link
Q9. Longest sub array with given sum. Link
Q10. Maximum Sub array sum (Kadane’s Algorithm) Link
Q11. 2 sum problem. Link
Q12. Sort an array of 0’s, 1’s and 2’s (Dutch National Flag Problem). Link
Q13. Majority Element in an array. Link
Q14. Leader in an array. Link
Q15. Maximum sum sub array of size k (Sliding window technique). Link

Strings Questions
Q1. Check if string is palindrome or not. Link
Q2. Check if strings are anagram or not. Link
Q3. Pangram checking of given string. Link
Q4. Count vowel in a string. Link
Q5. Convert Lower to upper case and upper to lower case in a string. Link
Q6. Longest common prefix. Link
Q7. Count number of sub string. Link
Q8. Remove spaces from a given string. Link
Q9. Encrypt the string. Link
Q10. Check if string is sub string of another. Link

Important Sorting Technique


Q1. Selection Sort Link
Q2. Bubble Sort Link
Q3. Insertion Sort Link
Q4. Merge Sort Link
Q5. Quick Sort Link

PYQ TCS -> Story based


Q1. Problem Statement –

Given a string S (input consisting) of ‘*’ and ‘#’. The length of the string is variable. The task is
to find the minimum number of ‘*’ or ‘#’ to make it a valid string. The string is considered
valid if the number of ‘*’ and ‘#’ are equal. The ‘*’ and ‘#’ can be at any position in the string.

Note: The output will be a positive or negative integer based on number of ‘*’ and ‘#’ in the
input string.
(*>#): positive integer
(#>*): negative integer
(#=*): 0
Example 1:
Input 1: ###*** -> Value of S
Output : 0 → number of * and # are equal

Q2. Given an integer array Arr of size N the task is to find the count of elements whose value
is greater than all of its prior elements.

Note : 1st element of the array should be considered in the count of the result. For example,
Arr[]={7,4,8,2,9} As 7 is the first element, it will consider in the result. 8 and 9 are also the
elements that are greater than all of its previous elements. Since total of 3 elements is
present in the array that meets the condition.
Hence the output = 3.
Example 1:
Input 5 -> Value of N, represents size of Arr
7-> Value of Arr[0]
4 -> Value of Arr[1]
8-> Value of Arr[2]
2-> Value of Arr[3]
9-> Value of Arr[4]
Output : 3

Q3. At a fun fair, a street vendor is selling different colours of balloons. He sells N number of
different colours of balloons (B[]). The task is to find the colour (odd) of the balloon which is
present odd number of times in the bunch of balloons.

Note: If there is more than one colour which is odd in number, then the first colour in the
array which is present odd number of times is displayed. The colours of the balloons can all
be either upper case or lower case in the array. If all the inputs are even in number, display
the message “All are even”.
Example 1: 7 -> Value of N [r,g,b,b,g,y,y] -> B[] Elements B[0] to B[N-1], where each input
element is sepārated by ṉew line.
Output : r -> [r,g,b,b,g,y,y] -> “r” colour balloon is present odd number of times in the bunch.
Explanation:
From the input array above: r: 1 balloon g: 2 balloons b: 2 balloons y : 2 balloons Hence , r is
only the balloon which is odd in number.

Q4. You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two
integers m and n,

representing the number of elements in nums1 and nums2 respectively.

Merge nums1 and nums2 into a single array sorted in non-decreasing order.

The final sorted array should not be returned by the function, but instead be stored inside the array
nums1. To

accommodate this, nums1 has a length of m + n, where the first m elements denote the elements
that should be

merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.

Example 1:

Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3

Output: [1,2,2,3,5,6]

Explanation: The arrays we are merging are [1,2,3] and [2,5,6].

The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
Q5. A party has been organized on cruise. The party is organized for a limited time(T). The number of
guests

entering (E[i]) and leaving (L[i]) the party at every hour is represented as elements of the array. The
task is to

find the maximum number of guests present on the cruise at any given instance within T hours.

Example 1:

Input :

5 -> Value of T

[7,0,5,1,3] -> E[], Element of E[0] to E[N-1], where input each element is separated by new line

[1,2,1,3,4] -> L[], Element of L[0] to L[N-1], while input each element is separate by new line.

Output :

8 -> Maximum number of guests on cruise at an instance.

Q6. There are total n number of Monkeys sitting on the branches of a huge Tree. As travelers offer
Bananas and Peanuts, the

Monkeys jump down the Tree. If every Monkey can eat k Bananas and j Peanuts. If total m number of
Bananas and p number

of Peanuts are offered by travelers, calculate how many Monkeys remain on the Tree after some of
them jumped down to eat.

At a time one Monkeys gets down and finishes eating and go to the other side of the road. The
Monkey who climbed down

does not climb up again after eating until the other Monkeys finish eating.

Monkey can either eat k Bananas or j Peanuts. If for last Monkey there are less than k Bananas left on
the ground or less than j

Peanuts left on the ground, only that Monkey can eat Bananas(<k) along with the Peanuts(<j).

Write code to take inputs as n, m, p, k, j and return the number of Monkeys left on the Tree.

Where, n= Total no of Monkeys

k= Number of eatable Bananas by Single Monkey (Monkey that jumped down last may get less than k
Bananas)

j = Number of eatable Peanuts by single Monkey (Monkey that jumped down last may get less than j
Peanuts)

m = Total number of Bananas

p = Total number of Peanuts


Remember that the Monkeys always eat Bananas and Peanuts, so there is no possibility of k and j
having a value zero.

Q7. The Caesar cipher is a type of substitution cipher in which each alphabet in the plaintext or
messages is shifted by a number of places down the alphabet.

For example, with a shift of 1, P would be replaced by Q, Q would become R, and so on. To pass an
encrypted message from one person to another, it is first necessary that both parties have the ‘Key’
for the cipher, so that the sender may encrypt and the receiver may decrypt it. Key is the number of
OFFSET to shift the cipher alphabet. Key can have basic shifts from 1 to 25 positions as there are 26
total alphabets.

As we are designing custom Caesar Cipher, in addition to alphabets, we are considering numeric
digits from 0 to 9. Digits can also be shifted by key places.

For Example, if a given plain text contains any digit with values 5 and key =2, then 5 will be replaced
by 7, “- ”(minus sign) will remain as it is.

Key value less than 0 should result into “INVALID INPUT”

Example 1: Enter your Plaintext: All the best

Enter the Key: 1

The encrypted Text is: Bmm uif Cftu

Q8. Sort one array according to another array You are given two arrays a[] (integer) and b[] (char).
The ith value of a[] corresponds to the ith value of b[].

Sort the array b[] with respect to a[].

Note: The output is whitespace and newline character sensitive. After every character print a
whitespace character. Also do not print any newline character at any point.

Example 1: Input: a[] = {3, 1, 2} b[] = {'G', 'E', 'K'}

Output: E K G

Explanation: Here 3 corresponds to G, 1 corresponds to 'E', 2 corresponds to 'K'


Q9. There are total n number of Monkeys sitting on the branches of a huge Tree. As travelers offer
Bananas and Peanuts, the

Monkeys jump down the Tree. If every Monkey can eat k Bananas and j Peanuts. If total m number of
Bananas and p number

of Peanuts are offered by travelers, calculate how many Monkeys remain on the Tree after some of
them jumped down to eat.

At a time one Monkeys gets down and finishes eating and go to the other side of the road. The
Monkey who climbed down

does not climb up again after eating until the other Monkeys finish eating.

Monkey can either eat k Bananas or j Peanuts. If for last Monkey there are less than k Bananas left on
the ground or less than j

Peanuts left on the ground, only that Monkey can eat Bananas(<k) along with the Peanuts(<j).

Write code to take inputs as n, m, p, k, j and return the number of Monkeys left on the Tree.

Where, n= Total no of Monkeys

k= Number of eatable Bananas by Single Monkey (Monkey that jumped down last may get less than k
Bananas)

j = Number of eatable Peanuts by single Monkey(Monkey that jumped down last may get less than j
Peanuts)

m = Total number of Bananas

p = Total number of Peanuts

Remember that the Monkeys always eat Bananas and Peanuts, so there is no possibility of k and j
having a value zero

Example 1:

Input Values -> 20 2 3 12 12

Output Values-> Number of Monkeys left on the tree:10

Note: Kindly follow the order of inputs as n,k,j,m,p as given

in the above example. And output must include the same

format as in above example(Number of Monkeys left on the

Tree:)

For any wrong input display INVALID INPUT


Q10. Airport security officials have confiscated several item of the passengers at the security check
point. All the items

have been dumped into a huge box (array). Each item possesses a certain amount of risk[0,1,2].
Here, the risk severity of

the items represent an array[] of N number of integer values. The task here is to sort the items based
on their levels of

risk in the array. The risk values range from 0 to 2.

Example:

Input:

7 -> Value of N

[1,0,2,0,1,0,2]-> Element of arr[0] to arr[N-1], while input each element is separated by new line.

Output :

0 0 0 1 1 2 2 -> Element after sorting based on risk severity

Q11. You are given an array prices where prices[i] is the price of a given stock on the ith

day.

You want to maximize your profit by choosing a single day to buy one stock and

choosing a different day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve

any profit, return 0.

Example 1:

Input: prices = [7,1,5,3,6,4]

Output: 5

Q12. Jack is always excited about sunday. It is favourite day, when he gets to play all day. And goes to

cycling with his friends.

So every time when the months starts he counts the number of sundays he will get to enjoy.
Considering

the month can start with any day, be it Sunday, Monday…. Or so on.

Count the number of Sunday jack will get within n number of days.

Example 1:

Input
mon-> input String denoting the start of the month.

13 -> input integer denoting the number of days from the start of the month.

Output :

2 -> number of days within 13 days.

Q13. There is an integer array ‘A’ of size ‘N’.

A sequence is successive when the adjacent elements of the sequence have a

difference of 1.

You must return the length of the longest successive sequence.

For example,

Input:

A = [5, 8, 3, 2, 1, 4], N = 6

Output: 5

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

Input -> nayannamantenet

Output->

nayan

naman

telnet

Q15. Problem Statement – An automobile company manufactures both a two wheeler (TW) and a
four wheeler (FW). A company manager wants to make the production of both types of vehicle
according to the given data below:

1st data, Total number of vehicle (two-wheeler + four-wheeler)=v

2nd data, Total number of wheels = W

The task is to find how many two-wheelers as well as four-wheelers need to manufacture as per the
given data.

Example :

Input :

200 -> Value of V

540 -> Value of W

Output :

TW =130 FW=70

Explanation:

130+70 = 200 vehicles

(70*4)+(130*2)= 540 wheels

Constraints :

2<=W

W%2=0

V<W

Print “INVALID INPUT” , if inputs did not meet the constraints.

The input format for testing

The candidate has to write the code to accept two positive numbers separated by a new line.

First Input line – Accept value of V.

Second Input line- Accept value for W.


Q16. A parking lot in a mall has RxC number of parking spaces. Each parking space will either
be empty(0) or full(1). The status (0/1) of a parking space is represented as the element of the
matrix. The task is to find index of the prpeinzta row(R) in the parking lot that has the most of the
parking spaces full(1).

Note :
RxC- Size of the matrix
Elements of the matrix M should be only 0 or 1.

Example 1:
Input :
3 -> Value of R(row)
3 -> value of C(column)
[0 1 0 1 1 0 1 1 1] -> Elements of the array M[R][C] where each element is separated by new line.
Output :
3 -> Row 3 has maximum number of 1’s

Q17. A washing machine works on the principle of Fuzzy System, the weight of clothes put inside it
for washing is uncertain But based on weight measured by sensors, it decides time and water level
which can be changed by menus given on the machine control area.

For low level water, the time estimate is 25 minutes, where approximately weight is between 2000
grams or any nonzero positive number below that.

For medium level water, the time estimate is 35 minutes, where approximately weight is between
2001 grams and 4000 grams.

For high level water, the time estimate is 45 minutes, where approximately weight is above 4000
grams.

Assume the capacity of machine is maximum 7000 grams

Where approximately weight is zero, time estimate is 0 minutes.

Write a function which takes a numeric weight in the range [0,7000] as input and produces
estimated time as output is: “OVERLOADED”, and for all other inputs, the output statement is

“INVALID INPUT”.

Input should be in the form of integer value –

Output must have the following format –

Time Estimated: Minutes


Example:
Input value
2000
Output value
Time Estimated: 25 minutes

Q18.

Problem Statement
A doctor has a clinic where he serves his patients. The doctor’s consultation fees are different for
different groups of patients depending on their age. If the patient’s age is below 17, fees is 200 INR. If
the patient’s age is between 17 and 40, fees is 400 INR. If patient’s age is above 40, fees is 300 INR.
Write a code to calculate earnings in a day for which one array/List of values representing age of
patients visited on that day is passed as input.
Note:

 Age should not be zero or less than zero or above 120


 Doctor consults a maximum of 20 patients a day
 Enter age value (press Enter without a value to stop):
Example 1:
Input
20
30
40
50
2
3
14
Output
Total Income 2000 INR
Note: Input and Output Format should be same as given in the above example.
For any wrong input display INVALID INPUT
Output Format
Total Income 2100 INR
Q19. Joseph is learning digital logic subject which will be for his next semester. He usually tries to
solve unit assignment problems before the lecture. Today he got one tricky question. The problem
statement is “A positive integer has been given as an input. Convert decimal value to binary
representation. Toggle all bits of it after the most significant bit including the most significant bit.
Print the positive integer value after toggling all bits”.

Constrains-

1<=N<=100

Example 1:

Input :

10 -> Integer

Output :

5 -> result- Integer

Explanation:

Binary representation of 10 is 1010. After toggling the bits(1010), will get 0101 which represents
“5”. Hence output will print “5”.

Q20. A supermarket maintains a pricing format for all its products. A value N is printed on each
product. When the scanner reads the value N on the item, the product of all the digits in the value N
is the price of the item. The task here is to design the software such that given the code of any item N
the product (multiplication) of all the digits of value should be computed(price).

Example 1:

Input :

5244 -> Value of N

Output :
160 -> Price

Explanation:

From the input above

Product of the digits 5,2,4,4


5*2*4*4= 160

Hence, output is 160.

Q21. A furnishing company is manufacturing a new collection of curtains. The curtains are of two
colors aqua(a) and black (b). The curtains color is represented as a string(str) consisting of a’s and
b’s of length N. Then, they are packed (substring) into L number of curtains in each box. The box
with the maximum number of ‘aqua’ (a) color curtains is labeled. The task here is to find the number
of ‘aqua’ color curtains in the labeled box.

Note :

If ‘L’ is not a multiple of N, the remaining number of curtains should be considered as a substring too.
In simple words, after dividing the curtains in sets of ‘L’, any curtains left will be another set(refer
example 1)

Example 1:

Input :

bbbaaababa -> Value of str

3 -> Value of L

Output:

3 -> Maximum number of a’s

Explanation:

From the input given above.

Dividing the string into sets of 3 characters each

Set 1: {b,b,b}

Set 2: {a,a,a}

Set 3: {b,a,b}

Set 4: {a} -> leftover characters also as taken as another set

Among all the sets, Set 2 has more number of a’s. The number of a’s in set 2 is 3.

Hence, the output is 3.


Q22. An international round table conference will be held in india. Presidents from all over the
world representing their respective countries will be attending the conference. The task is to find the
possible number of ways(P) to make the N members sit around the circular table such that.

The president and prime minister of India will always sit next to each other.

Example 1:

Input :

4 -> Value of N(No. of members)

Output :

12 -> Possible ways of seating the members

Explanation:

2 members should always be next to each other.

So, 2 members can be in 2!ways

Rest of the members can be arranged in (4-1)! ways.(1 is subtracted because the previously selected
two members will be considered as single members now).

So total possible ways 4 members can be seated around the circular table 2*6= 12.

Hence, output is 12.

Example 2:

Input:

10 -> Value of N(No. of members)

Output :

725760 -> Possible ways of seating the members

Explanation:

2 members should always be next to each other.

So, 2 members can be in 2! ways


Rest of the members can be arranged in (10-1)! Ways. (1 is subtracted because the previously
selected two members will be considered as a single member now).

So, total possible ways 10 members can be seated around a round table is

2*362880 = 725760 ways.

Hence, output is 725760.

You might also like