0% found this document useful (0 votes)
29 views15 pages

Coding Part 2

Uploaded by

ashutomar7014
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)
29 views15 pages

Coding Part 2

Uploaded by

ashutomar7014
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/ 15

TCS CODING

QUESTION 6-10
QUESTION - 6

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”.
QUESTION - 6

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.
QUESTION - 6

Example 2: Input: 10 -> Value of N Input Format for testing

[a,b,b,b,c,c,c,a,f,c] -> B[], elements B[0] to B[N-1] where input each element is The candidate has to write the code to accept: 2 input
separated by new line.
• First input: Accept value for number of N(Positive integer number).
Output : b-> ‘b’ colour balloon is present odd number of times in the bunch.
• Second Input : Accept N number of character values (B[]), where each value
Explanation: From the input array above: is separated by a new line.

• a: 2 balloons Output format for testing

• b: 3 balloons The output should be a single literal (Check the output in example 1 and
example 2)
• c: 4 balloons
Constraints: 3<=N<=50
• f: 1 balloons
• B[i]={{a-z} or {A-Z}}
Here, both ‘b’ and ‘f’ have odd number of balloons. But ‘b’ colour balloon
occurs first. Hence , b is the output.
QUESTION – 7

7) There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain
maximum N candies when JAR is full. At any point of time. JAR can have M number of Candies where
M<=N. Candies are served to the customers. JAR is never remain empty as when last k candies are left.
JAR if refilled with new candies in such a way that JAR get full. Write a code to implement above scenario.
Display JAR at counter with available number of candies. Input should be the number of candies one
customer can order at point of time. Update the JAR after each purchase and display JAR at Counter.
Output should give number of Candies sold and updated number of Candies in JAR.
If Input is more than candies in JAR, return: “INVALID INPUT”
Given, N=10, where N is NUMBER OF CANDIES AVAILABLE K =< 5, where k is number of minimum
candies that must be inside JAR ever.
QUESTION – 7

• Example 1:(N = 10, k =< 5)


• Input Value : 3
• Output Value : NUMBER OF CANDIES SOLD : 3
• NUMBER OF CANDIES AVAILABLE : 7
• Example : (N=10, k<=5)
• Input Value : 0
• Output Value : INVALID INPUT NUMBER OF CANDIES LEFT : 10
QUESTION – 8

8) Selection of MPCS exams include a fitness test which is conducted on ground. There will
be a batch of 3 trainees, appearing for running test in track for 3 rounds. You need to
record their oxygen level after every round. After trainee are finished with all rounds,
calculate for each trainee his average oxygen level over the 3 rounds and select one with
highest oxygen level as the most fit trainee. If more than one trainee attains the same
highest average level, they all need to be selected.
Display the most fit trainee (or trainees) and the highest average oxygen level
QUESTION - 8

Note:
• The oxygen value entered should not be accepted if it is not in the range between
1 and 100.
• If the calculated maximum average oxygen value of trainees is below 70 then declare
the trainees as unfit with meaningful message as “All trainees are unfit.
• Average Oxygen Values should be rounded.
QUESTION - 8

• Example 1: INPUT VALUES • OUTPUT VALUES :


• 95 • Trainee Number : 1
• 92 • Trainee Number : 3
• 95 Note:
• 92 Input should be 9 integer values representing oxygen levels
entered in order as
• 90
Round 1
• 92
• Oxygen value of trainee 1
• 90
• Oxygen value of trainee 2
• 92
• Oxygen value of trainee 3
• 90
QUESTION - 8

Round 1 Round 3
• Oxygen value of trainee 1 • Oxygen value of trainee 1
• Oxygen value of trainee 2 • Oxygen value of trainee 2
• Oxygen value of trainee 3 • Oxygen value of trainee 3
Round 2 Output must be in given format as in above
example. For any wrong input final output
• Oxygen value of trainee 1
should display “INVALID INPUT”
• Oxygen value of trainee 2
• Oxygen value of trainee 3
QUESTION – 9

• 9) Problem Statement
• 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.
QUESTION - 9

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
QUESTION - 9

Example:
Input value
2000
Output value
Time Estimated: 25 minutes
QUESTION – 10

10) Problem Statement


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
QUESTION – 10

For Example, if a given plain text contains any digit with values 5 and keyy =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
Write a function CustomCaesarCipher(int key, String message) which will accept plaintext
and key as input parameters and returns its cipher text as output

You might also like