Fun Game <Capillary>
Practice
3.4 (48 votes)
Data structures
Easy
Hiring
Queue
Stacks
Problem
49% Success 16586 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

\(A\) and \(B\)  are playing a game. In this game, both of them are initially provided with a list of \(n\) numbers. (Both have the same list but their own copy).

Now, they both have a different strategy to play the game. \(A\) picks the element from start of his list. \(B\) 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:

  1. If the number picked by \(A\) is bigger than \(B\) then this step's output is \(1\) . \(B\) removes the number that was picked from their list.
  2. If the number picked by \(A\) is smaller than \(B\) then this step's output is \(2\) . \(A\) removes the number that was picked from their list.
  3. If both have the same number then this step's output is \(0\) . Both $$A$$ and $$B$$  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.
  

Input format:

First line consists of a number \(n\) , size of the list provided.
Next line consists of \(n\) numbers separated by space.


Output format:

Output the required output list.


Constraints:

$$1 \le N \le 10^6$$
$$1 \le numbers \; in \; the \; list \le 10^9$$

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
10 votes
Tags:
Basics of StacksData StructuresStacksReal world
Points:20
44 votes
Tags:
Data StructuresEasyStacks
Points:20
53 votes
Tags:
Data StructuresDynamic programmingEasyStacks