TCS NQT To Be Shared - Coding
TCS NQT To Be Shared - Coding
TCS NQT To Be Shared - Coding
Coding
Q1 : M is an expert in Mathematics. He is performing arithmetic operations and wants to
find all the divisors of P number.
Note: Divisors should be separated by space and increasing order should be maintained.
Input format
Input containing a non-negative integer ‘P’ denoting the number
Violation of input criteria: System should display message as “Wrong Input”
Output Format
All divisors should be separated by space and increasing order must be maintained
Constraints
1 <= P <= 10^8
Sample 1
Input
10
Output
1 2 5 10
Q2: Alex has been preparing a box for handicraft. The box consists of N pieces of stones
with each stone having a certain weight assigned to it. Each stone in the box will carry a
different weight. This means no two stones can have the same weight
Alex wants to do this by making minimal changes in the original weight at least as much
as its original weight
Find the minimum total weight that he can set for the box.
Note: Stone weight are not in float value.
Input
1. First input contains N, the total number of stones in the box
2. Second Input contains N sorted integers separated by newline A1, A2...An,
representing the original weights assigned to each stone violation of input criteria:
System should display message as “Wrong Input”.
Output
The minimum total stone weights Alex can set the box for
Constraints
1<=N<=100000
1<=A[i]<=100000
Example 1:
Input
3
2
2
4
Output
9
www.learningabode.in Page 1
TCS NQT / Ninja / TCS Off-Campus
Coding - From Previous Papers
Q4 : A customer purchases one or more items and gives the respective quantity for each
time to be purchased. Based on the quantity and price of the items, display the final
amount after discount. A customer is eligible for 10% discount on total purchase price
above Rs. 1000. For total purchase price Rs. 1000, no discount is given.
Check is customer has a membership with the store.
If he is member, then he gets an extra 5% discount on every purchase, but if purchase
amount of member is alone Rs.1000 then he gets total discount of 15% on purchase price.
www.learningabode.in Page 2
TCS NQT / Ninja / TCS Off-Campus
Coding - From Previous Papers
For example, if Rajesh does purchase of Rs.1800 which is above Rs.1000 and he is not
member of store ge gets discount of 10%.
But, if Rajesh is member of store then he gets total 15% discount on Rs. 1800 since its
above Rs.1000, but if he does purchase of Rs.800 which is below Rs.1000 then he gets
only discount of 5%.
Given, items and price
Item No Items Price
1. Yoghurt 50
2. Cheese 100
3. Mlik 40
4. Fruit 200
5. Oil 300
Calculate the actual price customer has to pay.
Example 1:
135
216
Y
1649.0INR
Note:
1. Order of input should be as given in above example
<ItemNumber> space <ItemNumber> space……
<Quantity> space <Quantity> space……
(you can enter any item numbers from 1 to 5 only else display INVALID INPUT)
{You must enter quantity as many times as to match with ItemNumber entered else
display INVALID INPUT)
2. Output format should match with the format
Q5: A food court facilitates their customers with a featured App where the customers can
view the Menu Card and place their order. The order may be delivered on-premises as per
policies. Write a code to take the order from the customers by pressing
menu number
Quantity
After one customer completes the process of placing the order by pressing the Menu
number and Quantity. Your code should accept y to continue taking order or n for
stopping the process of order taking
Final output should be the calculated total amount.
Menu card is given as
Number Name Price
1. Veg sandwich 80.0
2. Cheese sandwich 130.0
3. Veg Grilled sandwich 100.0
4. Sada Dosa 80.0
5. Masala Dosa 90.0
www.learningabode.in Page 3
TCS NQT / Ninja / TCS Off-Campus
Coding - From Previous Papers
Q6: Indian Premier League IPL Cricket Matches are organized for a few Days. The
problem is to prepare Timetable from Day1 to Day n, where n depend on the teams
participating. Set A represent the names of teams participating. Set A will be input from
the user. Do not show input user message directly accept the teams names as string values
and enter q to stop taking inputs.
Write a code to display Pairing of Teams and possible number of matches possible
excluding Semi Final and Final.
Note: Minimum 3 Teams are required and maximum limit of Teams is 12.
Example 1
Input Values
CHENNAI
MUMBAI
KOLKATA
PATNA
Q
Output Values
TOTAL MATCHES: 6
CHENNAI-VS- MUMBAI
CHENNAI-VS-KOLKATA
www.learningabode.in Page 4
TCS NQT / Ninja / TCS Off-Campus
Coding - From Previous Papers
CHENNAI-VS-PATNA
MUMBAI-VS-KOLKATA
MUMBAI-VS-PATNA
KOLKATA-VS-PATNA
Q7: Take a single line text message from user. Separate the vowels from the text. Find
the repeating occurrences of vowels from the text message.
Display count of which vowels has repeated how many times.
Display a new text message by removing the vowels characters as output.
Display the output in the exact format shown below in example, after displaying count of
characters on next lines display the new text message on next line.
“Hll wlcm” is the next text message.
If text message entered by user does not contain any vowels then display 0 as output.
If text message entered by user contain any numeric value then display 0 as output.
If user entered blank or empty text message display “INVALID INPUT” as output.
Message “INVALID INPUT” is case sensitive. Display it in exact format given
Example 1:
Input:
Hello welcome
Output
a:0
e:3
i:0
o:2
u:0
Hll wlcm
www.learningabode.in Page 5