are playing a game. In this game, both of them are initially provided with a list of
numbers. (Both have the same list but their own copy).
Now, they both have a different strategy to play the game.
picks the element from start of his list.
picks from the end of his list.
You need to generate the result in form of an output list.
Method to be followed at each step to build the output list is:
- If the number picked by is bigger than then this step’s output is . removes the number that was picked from their list.
- If the number picked by is smaller than then this step’s output is . removes the number that was picked from their list.
- If both have the same number then this step’s output is . Both and remove the number that was picked from their list.
This game ends when at least one of them has no more elements to be picked i.e. when the list gets empty.
Output the built output list.
First line consists of a number
, size of the list provided.
Next line consists of
numbers separated by space.
Output the required output list.
1st step: A picks 1. B picks 3. B > A. So output is 2. A removes 1.
2nd step: A picks 2. B picks 3. B > A. So output is 2. A removes 2.
3rd step: A picks 3. B picks 3. B = A. So output is 0. A removes 3. B removes 3.
Output list: [2, 2, 0]