TCS Problem
TCS Problem
In this superhero epic, the denizens of the Marvel Universe are forced to pick sides when Captain
America and Iron Man come to blows over ideological differences.
The government decides to push for the Hero Registration Act, a law that limits a hero’s actions. This
results in a division in The Avengers. Iron Man stands with this Act, claiming that their actions must be
kept in check otherwise cities will continue to be destroyed, but Captain America feels that saving the
world is daring enough and that they cannot rely on the government to protect the world. And here the
civil war begins.
They are trying make their team stronger by adding more avengers to their team. There are N avengers
lined up.
Any team can start rst. But they will alternatively only.
They can select avenger from any side. But if they start from one side they can’t move to other
side in current chance.
They can select consecutive avengers as many they want. They will stop only when all the
avengers are part of either side.
Every Avenger has a power associated with him
There are some spurious avengers who will decrease the overall power of the team.
Both teams will select players optimally. Find the difference of powers of the two teams
Constraints
Input
First line contains an integer denoting the number of Avengers(N). Next lines contain N
space separated values denoting power of every avenger(P[i]).
Output
Examples :
Input
2-78-1 20
Output
Problem – 2 : Encryption
John is working in high security organization, where he needs to deal with lot of con dential documents.
He must encrypt the important number in documents. Please help John to write a program where the
system should identify the integer number and encrypt number based on John’s actions.
Rules
When incrementing the value of a number at a current location, if the number is 9 then it
remains 9 else it increases by 1.
When decrementing the value of a number at a current location, if the number is 0 then it
remains O else it decreases by 1.
Once all the actions from the action string are consumed, if any part of the input string
remained unprocessed then leave those characters of the input string as they are.
Constraints
Input
First line contains a string comprising of numbers. This is referred to as input string in the rest of the
document.
Second line contains the actions denoted by values mentioned in the table above. This is referred to as
action string in the rest of the document.
Output
Examples
Input
123456
RLTDRRTRS2S1
Output
244156
Explanation
Action: RLTDRRTRS2S1
R: 1[2]3456
L: [1]23456
T: [2]23456
D: [1]23456
R: 1[2]3456
R: 12[3]456
T:12[4]456
R: 124[4]56
S2: 144[2]56
S1: 244[1]56
output string.
Since all the actions from the action string are consumed and only rst four characters of the input string
are processed leave the last two as they are and make them the part of
You are given N comma-separated Strings. You need to form all possible legal subsets of these N strings.
These subsets will be a combination of zero or more of these N Strings After forming the subsets, they
will be ranked in a particular onder. The legal subset formation and ranking logic is as described below
Next N ranks will be the N Strings that appear in the order they are provided in the input
After N + 1 ranks, you need to combine N strings such that all legal combinations are formed
Legal combination simply means that while combinations are formed, the string that appears to
the left of a particular string in the input, can never appear to the right of that particular string,
when subsets are formed
A subset with less elements will be ranked higher than a subset with more elements (NOTE-Rank
1 is higher than rank 2)
Refer Example 2 to get a better understanding of how subsets are formed and ranked
It is guaranteed that
N>=1
Example: you are having an input string “aa,cc,bb” in this string we can see we have three strings which
are comma separated. Now from this group of string we have to create all possible subset of strings. 8
subsets can be formed from these strings. And they are as follows:
{}
{ aa}
{ cc}
{ bb}
{ aa,}
Note: here we can see the ranks given to the subsets are rst by size i.e. , the subset with lesser number
of strings is ranked higher than the subset with higher size. If the subsets have equal number of strings
then, the combination which is formed earlier (by virtue of combining strings in order they appear in
input), gets a higher rank.
For example, rank of su bset (aa,cc) > rank of (aa,bb) because string cc is appearing prior to string bb in
the input. Similarly, rank of (cc) > rank of (bb). You are provided one rank R and for that you have to
print the Rth subset from all legal subsets.
Constraints:
0<N<=10^2
0<R<=10^18
Input
Second line contains an integer R, for which you have to find Rth subset from all legal subsets.
Third line contains N comma-separated strings basis which the subsets should be formed.
Output:
Input
a,b
Output
a,b
Explanation:
{a} -2
{b}-3
{a, b}-4
You are a caretaker of a waiting room and you have to take care of empty seats such that all the people
should sit together. Imagine the seats are in a straight line like in a movie theatre. People are seated on
random seats initially. Your task is to make them sit together so that minimum number of people change
their position. Also, they can be made to sit together in many ways. Find the number of ways you can
make them sit together by requiring only minimal people movement.
“E” depicts an empty seat and “O” depicts an occupied seat. Input will be given in the form of a string.
Example: OEOEO
As we can see, only seat number 1, 3, 5 are occupied and 2 and 4 are empty.
Case 1: If we move 5th person to 2nd position, they can all be together with only one person moving
his/her place.
Case 2: If we movement 1st person to 4th position, they can all be together with only one person
moving his/her place.
They can all be together with only one movement and this can be done in 2 ways. Print the minimum
number of movements required and the number of ways this minimum movement can help achieve the
objective.
Constraints
Input
Second line contains N characters each of which are either “O” or “E”. “O” denotes an occupied seat and
“E” denotes an empty seat.
Output
Print minimum number of movements required and the number of ways in which all people can be
made to sit together without exceeding minimum number of movements by space
Examples
Input
OEOEO
Output
12
Explanation:
Seat number 2 and 4 are unoccupied and all the other seats are occupied.
We can make them sit together by moving only one person near to the other. It can be done in 2 ways:
You are given N number of coordinates and you have to create a polygon from these points such that
they will make a polygon with maximum area.
Note: coordinates provided in the input may or may not be in sequential form.
Constraints
1<=N<=10
Input:
Next N lines consist of two space separated integer depicting coordinates of in form of xy
Output:
Print the maximum possible area possible by creating a polygon by joining the coordinates. If the area is
in decimal form, print the absolute value as output.
Examples:
Input:
00
20
02
22
Output:
Explanation:
As we can imagine that these points will make a square shape and the maximum possible area made by
the polygon will be 4.
Problem – 6 : Bank Compare Problem
Problem – 7 : Bank Compare Problem
Problem – 8 : Consecutive Prime Sum
Problem – 9 : Counting Rock Sample
Problem – 10 : kth Largest factor of N
Problem – 11 : Collecting Candies