Minimum Number Game

You are given a 0-indexed integer array nums of even length and there is also an empty array arr. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:

  • Every round, first Alice will remove the minimum element from nums, and then Bob does the same.
  • Now, first Bob will append the removed element in the array arr, and then Alice does the same.
  • The game continues until nums becomes empty.

Return the resulting array arr.

Example 1
Inputnums = [5,4,2,3]
Output[3,2,5,4]
In round one Alice removes 2 and Bob removes 3, so Bob appends 3 then Alice appends 2; in round two Alice removes 4 and Bob removes 5, so the final array is [3, 2, 5, 4].
Example 2
Inputnums = [2,5]
Output[5,2]
Alice removes 2 and Bob removes 5, then Bob appends 5 and Alice appends 2, giving [5, 2].

Constraints

  • 2 <= nums.length <= 100
  • 1 <= nums[i] <= 100
  • nums.length % 2 == 0

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate