TCS NQT To Be Shared - Coding

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

TCS NQT / Ninja / TCS Off-Campus

Coding - From Previous Papers

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

Q3 : A customer has a choice to buy TV from set of 3 company models provided by


store.
If customer take an exchange offer.
 Then customer get discount of 2% is old TV is not in working condition
 Customer gets discount of 20% if old TV is in working condition
If customer do not opt for exchange offer then, he has to pay MRP of TV as amount
Display the amount of customer has to pay.
Menu for TV condition should be displayed only if customer choose for exchange offer
When user enters invalid option then code should stop with message “INVALID
INPUT”, it should be displayed in same format as it is case sensitive.
Make sure output text should be in exact format mentioned above
Assume following List is already seen by customer, There should be 3 inputs for each
question whose answer should be a number given with that choice.
First input choice
Display List (Select TV Model)
1. Samsung 10000
2. Onida 7000
3. HDLC 6000
Second Input Choice
Want to take Exchange Offer
1. Yes
2. No
Third Input Choice
Current Condition of customer’s old TV
1. Working
2. Not Working
For example, if customer want TV HDLC and he want to opt exchange offer for his old
TV which is in working condition then output will be 4800.0 INR
All input values should be entered in Following Format
3
1
1
Output 4800.0 INR
Note that when customer do not opt for exchange offer, there will be only 2 inputs.

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

6. Onion Rava Sada Dosa 110.0


7. Onion Rava Masala Dosa 120.0
8. Spring Dosa 140.0
9. Plain Uttapam 70.0
10. Onion Uttapam 80.0
You can use any suitable data structure to hold the menu card items with price.
Inputs for Menu Number and Quantity should be integers greater than 0 and less than 21.
For any other input, return as output: INVALID INPUT
Example 1
INPUT VALUES
1 //for enter menu number
2 //for enter quantity
Y //Do you want to order
More Items? (y/n)
2 //for enter menu number
3 //for enter quantity
N //Do you want to order
More items? (y/n)
Output values
Total Amount : 550.0 INR
Note: Input prompt should not be the part of code
(Only accept values as input in order as given above)
Output should be in the format given above.

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

You might also like