Skip to main content

TCS Coding Questions

 

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

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

1 3 5

2 1 6

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

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

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

 

Comments

Popular posts from this blog

All TCS preparation resources in a single link

  Tata Consultancy Services (TCS) the Indian multinational information technology services and consulting company, a global leader in IT services, consulting & business solutions recruits more than 25000   to 40000 graduates every year. The Major TCS fresher hiring (On-Campus & Off-Campus) includes 1. TCS Ninja & TCS Digital 2. TCS Smart Hiring (IT) 3. TCS BPS Hiring 4. TCS Management Hiring TCS also recruits the fresher’s for all the above four through TCS NQT held 4 times a year, which is a qualifying exam for which the candidates have to choose, pay and write the different variants available based on their career choice.   For all the 5 hiring including the TCS NQT, the written test is conducted by TCS ION, a strategic unit of Tata Consultancy Services focused on Manufacturing Industries (SMB), Educational Institutions and Examination Boards. TCS NQT (Paid), TCS Smart Hiring, TCS BPS hiring have the cognitive test which is similar for all of...

Tech Mahindra July 2023 - ASE Hiring Official Information

  Tech Mahindra is one again hiring 2022 & 2023 batch and the registration for the hiring closes very soon. This video has the complete details of this Tech Mahindra Hiring of B.E/B.Tech/MCA/MSc. Previous Links https://www.learningabode.in/2022/05/tech-mahindra-selection-process-pattern.html

HCLTech hiring Graduate Trainee

Dear Friends,    This post is to inform about HCLTech Hiring Graduate Trainees  Job Title- Graduate Trainee (Global Service Desk) Qualification- BCA,  B.Sc  (CS/IT) Criteria—60% and above throughout the academics (10th, 12th and UG) Location- PAN India Batch-2022 and 2023 Click the link below to apply: https://freshers.hcltech.com/?utm_source=OffCampus&utm_medium=GT&utm_campaign=BCA&BSC Click the link below for the source https://www.linkedin.com/feed/update/urn:li:activity:7061411938643099648/