0% found this document useful (0 votes)
48 views19 pages

TCS Problem

Uploaded by

Tushar Chandel
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)
48 views19 pages

TCS Problem

Uploaded by

Tushar Chandel
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/ 19

Problem – 1 : Civil War

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.

Rules to add avenger to their team-

 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

1<= N <= 10^6

-10^9 <= p[i] <= 10^9

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

Print the difference of the powers of teams

– Time Limit (secs) 1

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.

John’s actions are as follows


Actions Denoted by Remarks
Right arrow R Move to next character

Left arrow T Move to previous character

Up arrow L Increment the integer by one

Down arrow D Decrement the integer by one

Swap Sn Swap the current position with number in the nth


position

These actions are governed by the rules mentioned below.

Rules

 Initial position is at the rst character of the string comprised of numbers.

 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

0 <n<= I where I is length of the input string.

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

Single string comprising of numbers.

Time Limit (secs)

Examples

Input

123456

RLTDRRTRS2S1

Output

244156

Explanation

Initial string: 123456

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

Problem – 3 : Possible Legal Subsets

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

 Rank 1 will always be an empty set

 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

 All N strings are unique

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

First line contains an integer N which is number of strings in group.

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:

From all possible legal subsets nd the subset whose rank is R

Time Limit (secs)

Input

a,b

Output

a,b

Explanation:

Given that N = 2, given

Second line: Rank to be nd: 4th

Third line: Given group of strings: a,b

Possible subsets & Rank


{}-1

{a} -2

{b}-3

{a, b}-4

Output– a,b (4th rank corresponds to a,b)

Problem – 4 : Seating Arrangement

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.

Note: If they are already sitting together, Print “00” as output.

Constraints

0 <N <= 100000

Input

First line contains an integer N which depicts the number of seats

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

Time Limit (secs)

Examples

Input

OEOEO

Output

12

Explanation:

Given data of 5 seats in the queue,

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:

OOOEE (Moving 4 person to 2º position)

EE000 (Moving 1 person to 4 position)


Problem - 5 : Polygon with Maximum Area

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:

First line contains an integer N which depicts number of co-ordinates

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.

Time Limit (secs):

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

Problem – 12 : Staircase Problem


Problem – 13 : Maneuvering a Cave Problem

Problem – 14 : Houses Problem


Problem – 15 : Square Free Numbers Problem
Problem – 16 : Coin Distribution Problem
Problem – 17 : Total Distance Covered by the Beetle

You might also like