Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views18 pages

TCS IPA Coding Practice Qs

The document contains a series of coding practice questions for TCS IPA, categorized into easy and medium-hard levels. Each question provides a specific problem statement, input/output formats, and sample inputs/outputs to guide the coding solution. The problems range from reversing numbers to analyzing player statistics in a sports league.

Uploaded by

Prayas Dash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views18 pages

TCS IPA Coding Practice Qs

The document contains a series of coding practice questions for TCS IPA, categorized into easy and medium-hard levels. Each question provides a specific problem statement, input/output formats, and sample inputs/outputs to guide the coding solution. The problems range from reversing numbers to analyzing player statistics in a sports league.

Uploaded by

Prayas Dash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

TCS IPA Coding Practice Questions

(Comprehensive Input/Output Samples for Each Question)

� Easy-Level Coding Questions

Q1: Reverse the Number Mystery

Background:
Raju is fascinated by numbers and enjoys playing little mind games. One day, his friend challenged
him: “If I give you any non-negative number, can you quickly tell me its exact reverse (excluding
leading zeros)?” Raju is confident, but now it’s your turn—can you help him?

What To Do?
Given a non-negative integer, print its reversed digits as a number (no leading zeros in the result).

Input Format:

 Single line: a non-negative integer N (0 ≤ N ≤ 1,000,000,000).

Output Format:

 Print: Reverse of the number is X.


(Where X is the reversed number)

Sample Input

1234500

Sample Output

Reverse of the number is 54321.

Sample Input

Sample Output

Reverse of the number is 5.

Sample Input

0
Sample Output

Reverse of the number is 0.

Sample Input

900

Sample Output
Reverse of the number is 9.

Q2: The Airport Tag Sorter

Background:
At Mapleleaf Airport, baggage tags mix up due to a technical glitch. Each tag gets printed as a
jumbled string of passenger name initials (letters) and ticket numbers (digits). The data entry
operator must separate these into two fields for further processing.

What To Do?
Given such a string, extract all alphabets (in order) as one string, and all digits (in order) as another
integer. Print the result as a list.
If there is only letters or only digits, only print the existing one in the list.

Input Format:

 A single line containing only uppercase/lowercase letters and digits.

Output Format:

 [letters_string, digits_integer]

 If letters missing: [digits_integer]

 If digits missing: [letters_string]

Sample Input
A53b7W2

Sample Output

[AbW, 5372]

Sample Input

32451

Sample Output

[32451]

Sample Input
abcDEF

Sample Output
[abcDEF]

Sample Input

B0a1C9

Sample Output

[BaC, 019]

Q3: Theme Park Parking Puzzle

Background:
Imagine a special event at Rainbow Theme Park. The parking manager records only two values: the
total number of vehicles in the parking lot and the total number of wheels. All vehicles are either
two-wheelers or four-wheelers. Based on these two numbers, the security staff must quickly find out
how many two-wheelers and four-wheelers have entered—so they can organize exit lanes!

What To Do?
Given total vehicles (V) and wheels (W), compute the exact number of two-wheelers (TW) and four-
wheelers (FW).
If such a division is impossible (for instance, number of wheels is odd, or numbers just don't match
up), print "Invalid input".

Input Format:

 First line: V (integer)

 Second line: W (integer)

Output Format:

 If possible: TW = t FW = f

 If not possible: Invalid input

Sample Input
200
540

Sample Output

TW = 130 FW = 70

Sample Input

10
25

Sample Output

Invalid input

Sample Input
2
8

Sample Output

TW = 0 FW = 2

Sample Input

6
15

Sample Output
Invalid input

Sample Input
4
10

Sample Output

TW = 3 FW = 1

Q4: Unique-Digit Number Finder

Background:
In a logical math quiz, the host asks: within any given range of numbers, how many numbers have
all unique digits (i.e., in ‘122’, digit ‘2’ repeats, so it’s not unique—but ‘123’ is)? Your job is to
automate this check for the quizmaster.

What To Do?
Given two integers L and U, count all numbers in the range [L, U] that have all unique digits. If none,
print NoUnique Number.

Input Format:

 Line 1: L (integer, lower bound)


 Line 2: U (integer, upper bound; L ≤ U)

Output Format:

 If at least one unique-digit number exists: print its count.

 If none: print NoUnique Number

Sample Input

10
15

Sample Output

Sample Input

121
125

Sample Output

Sample Input

1010
1012

Sample Output
NoUnique Number

Sample Input
100
100
Sample Output

Q5: Range Average — Game Show Edition

Background:
You're in a fun game show! You’ll be given 5 scores at the start. Then, the host asks you to pick only
those scores that are more than a given "lower limit" and less than a given "upper limit", and find
their integer average (rounded down). If no scores meet the criteria, your answer should be 0.

What To Do?
Print the average of numbers in (lower limit, upper limit). If none, print 0.

Input Format:

 First line: 5 integers (space-separated)

 Second line: 2 integers (lower limit and upper limit; space-separated)

Output Format:

 Average value (integer division), or 0.

Sample Input
100 200 300 400 500
100 500

Sample Output

300

Sample Input

12345
10 20

Sample Output

0
Sample Input

150 250 350 450 550


200 400

Sample Output
300

Sample Input

90 80 70 60 50
49 90

Sample Output
70

� Lengthy/Medium-Hard Coding Questions

Q6: The Hospital Pharmacy Database

Background:
CityCare Hospital maintains a digital inventory for all medicines in its pharmacy. Each medicine is
identified by its name, batch number, disease it treats, and price. Doctors and pharmacists often
request all available medicines for a particular disease—so they can compare and prescribe the most
affordable or suitable one.

Last week, the Chief Pharmacist wanted a sorted list of prices for all medicines that can treat a
specific disease (regardless of letter case, since input may vary). He assigns this problem to you,
hoping you can automate their search and help streamline hospital operations.

What To Do?

 Write a program using a Medicine class (attributes: name, batch, disease, price).

 For a queried disease (string, case-insensitive), output all prices of matching medicines in
ascending order.

 If no medicines found for that disease, print "No medicines found".


Input Format:

 First line: N (number of medicines/entries)

 Next N lines: name batch disease price (space-separated)


(For example: Paractin B001 Fever 40)

 Last line: Disease you want to search for

Output Format:

 List of prices (ascending, space-separated), or

 No medicines found

Sample Input

4
Paractin B001 Fever 40
Zycin Z113 Cold 55
Fevgo F110 Fever 30
Azitro A123 Cold 70
Fever

Sample Output
30 40

Sample Input

3
Panadol B100 Flu 50
Cetrizine B200 Allergy 20
Ascoril B300 Cough 45
Headache

Sample Output
No medicines found

Sample Input
2
Dolopar X19 fever 40
Thermolin F11 FEVER 30
FEVER

Sample Output

30 40

Q7: The Diligent Account Holder

Background:
Mrs. Sharma has opened a bank account with strict minimum balance rules: her account must always
stay at or above ₹1,000. She deposits and tries to withdraw some amount. Withdrawal is permitted
only if after the transaction, her balance is still at least ₹1,000; else, it is declined. The bank system
must help her and the teller by clearly showing balances after each operation and guiding them if a
withdrawal is disallowed.

What To Do?

 Create an Account class with: account number, holder name, and balance.

 Provide deposit(amount) and withdraw(amount) methods.

 Withdrawal succeeds only if the remaining balance does not drop below ₹1,000.

 Print balance after each operation. If withdrawal fails, output "Insufficient balance for withdrawal".

Input Format:

 Line 1: Integer (account number)

 Line 2: String (holder name)

 Line 3: Integer (starting balance)

 Line 4: Integer (deposit amount)

 Line 5: Integer (withdrawal amount)

Output Format:

 Balance after deposit : <balance_after_deposit>

 Either:

o Balance after withdrawal : <balance_after_withdrawal>, or

o Insufficient balance for withdrawal


Sample Input

101456
Anil Kumar
1350
500
900

Sample Output
Balance after deposit : 1850
Insufficient balance for withdrawal

Sample Input

125789
Sneha Sen
1500
200
500

Sample Output

Balance after deposit : 1700


Balance after withdrawal : 1200

Sample Input

100111
Rahul Jain
1200
100
300

Sample Output
Balance after deposit : 1300
Balance after withdrawal : 1000

Sample Input
200200
Amit Roy
1200
500
800

Sample Output

Balance after deposit : 1700


Insufficient balance for withdrawal

Q8: The League’s Player Analyzer

Background:
Cricket stat-keepers in a sports league have a vast table of player data. They often need (1) the
player with the least runs within a specific player type (e.g., Bowler, Batsman), and (2) a list of all
player IDs (sorted by descending ID) for a specific match type (e.g., ODI, Test).
For better team selection and analysis, automate these two queries for them!

What To Do?

 Define a Player class: id, name, run, ptype (player type), mtype (match type).

 For a queried player-type, print the lowest run scored by any such player, or 0 if none.

 For a queried match-type, print IDs of all players for that type, in descending order, or nothing
if none.

Input Format:

 Line 1: Integer N (no. of players)

 Next N lines: id name run ptype mtype

 Next line: Player type to query (e.g., Bowler)

 Next line: Match type to query (e.g., ODI)

Output Format:

 Line 1: Least run for player type (or 0 if none)

 Line 2: Matching player IDs (descending, space-separated) for match type (blank if none)

Sample Input
3
10 Rahul 80 Bowler ODI
11 Ashwin 100 Batsman ODI
12 Kohli 40 Bowler Test
Bowler
ODI

Sample Output

80
11 10

Sample Input

4
15 Smith 70 Batsman Test
21 Clark 45 Bowler ODI
9 Ron 67 Bowler ODI
18 Lee 56 Batsman ODI
Batsman
ODI

Sample Output
56
18

Sample Input

2
25 Joe 90 Bowler Test
32 Max 100 Bowler Test
Batsman
ODI

Sample Output

Sample Input
2
5 Alan 25 Allrounder T20
9 Steve 40 Allrounder T20
Bowler
T20

Sample Output

0
95

Q9: Hidden Number in the Confidential Memo

Background:
Your company’s security department hides operational codes inside textual memos. But, for safety,
no code is allowed to contain the digit 9! Given such a secret memo, it’s up to you to scan and find
the largest hidden number that doesn’t have any digit 9.

What To Do?

 Read a line containing text and numbers (space-separated).

 From all numbers, print the largest one that does not contain the digit 9.

 If there is no such number, print -1.

Input Format:

 Single line of text and/or space-separated numbers.

Output Format:

 The largest valid number (without digit 9) or -1

Sample Input

This is alpha 5057 and 97

Sample Output
5057

Sample Input

99 91 9

Sample Output
-1

Sample Input

10 209 45 890 100

Sample Output

100

Sample Input

a1 b2 c3

Sample Output
3

Sample Input
nothing matches here

Sample Output
-1

Q10: Laptop Store Query System

Background:
TechieWorld, a city electronics store, maintains detailed records of all laptops: their brand, operating
system (OS), and customer rating (out of 5).
The manager wants to make two types of quick reports:

1. For a given brand, count how many laptops are highly rated (rating above 3).

2. For a specific OS, find all indices (starting from 0) where that OS is used.

Your software will help managers instantly answer such queries for sales decisions.

What To Do?

 Use a Laptop class: brand (String), os (String), rating (int).

 Print the count of laptops of a specified brand with rating > 3.

 Print all indices (space separated) for laptops with the specified OS, or -1 if there are none.

Input Format:

 First line: N (number of laptops)

 Next N lines: brand os rating

 Next line: brand to check

 Next line: OS to check

Output Format:

 Line 1: count (for brand and rating)

 Line 2: all matching indices for OS (space-separated) or -1

Sample Input

4
Dell Windows 4
Lenovo Linux 3
Dell Windows 5
HP Windows 2
Dell
Windows

Sample Output
2
02
Sample Input

3
Acer Linux 2
Asus Windows 5
Acer Windows 4
Asus
Linux

Sample Output

1
0

Sample Input

5
Dell Ubuntu 5
HP Ubuntu 4
Lenovo Ubuntu 2
Acer Ubuntu 5
Dell Ubuntu 2
Dell
Windows

Sample Output

1
-1

Sample Input

2
Apple Mac 4
Apple Windows 4
Apple
Mac
Sample Output

2
0

You might also like