Build the Result of a Two-Player Minimum-Removal Game
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
# Build the Result of a Two-Player Minimum-Removal Game
You are given a 0-indexed integer array `nums` of even length. Start with an empty result array `arr` and repeat these rounds until no elements remain:
1. Alice removes a minimum element from the remaining array.
2. Bob removes a minimum element from what remains after Alice's removal.
3. Bob appends his removed value to `arr`, then Alice appends hers.
Return the resulting array `arr`.
### Examples
**Example 1**
```text
Input: nums = [8,1,6,3,3,7]
Output: [3,1,6,3,8,7]
```
Alice and Bob remove values `1` and `3` in the first round, then append `3,1`. In the second round they remove `3` and `6`, then append `6,3`. In the last round they remove `7` and `8`, then append `8,7`.
**Example 2**
```text
Input: nums = [4,4]
Output: [4,4]
```
Both removed values are `4`, and Bob's value is appended before Alice's. The two occurrences are both retained in the result.
### Constraints
- `2 <= nums.length <= 100`.
- `1 <= nums[i] <= 100`.
- `nums.length % 2 == 0`.
### Clarifying Questions
- Does Alice or Bob remove first? Alice removes first in every round.
- Does Alice or Bob append first? Bob appends first in every round.
- Does Bob select from the original array before Alice's removal? No; Bob selects a minimum from the remaining elements afterward.
- Can equal minimum values occur? Yes; no uniqueness guarantee is given. Removing either equal occurrence gives the same sequence of output values.
- Must a game strategy be optimized? No; follow the specified rules and return their result.
### C++ Interface
```cpp
class Solution {
public:
vector<int> numberGame(vector<int>& nums) {
}
};
```
### Reasoning Checkpoints
- Preserve both the removal order and the different append order.
- Account for duplicate values and every original occurrence.
- Use the even-length guarantee so every round has exactly two removals.
```hint Organize the successive minima
If the input values were listed in nondecreasing order, which two would Alice and Bob remove in the first round? Which two remain next, and in what order should each round's values be appended?
```
Overview: Follow rounds where Alice and Bob remove the remaining minima in that order but append Bob’s value before Alice’s, returning the complete game result.
Build the Result of a Two-Player Minimum-Removal Game
Amazon
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Build the Result of a Two-Player Minimum-Removal Game
You are given a 0-indexed integer array nums of even length. Start with an empty result array arr and repeat these rounds until no elements remain:
Alice removes a minimum element from the remaining array.
Bob removes a minimum element from what remains after Alice's removal.
Bob appends his removed value to
arr
, then Alice appends hers.
Return the resulting array arr.
Examples
Example 1
Input: nums = [8,1,6,3,3,7]
Output: [3,1,6,3,8,7]
Alice and Bob remove values 1 and 3 in the first round, then append 3,1. In the second round they remove 3 and 6, then append 6,3. In the last round they remove 7 and 8, then append 8,7.
Example 2
Input: nums = [4,4]
Output: [4,4]
Both removed values are 4, and Bob's value is appended before Alice's. The two occurrences are both retained in the result.
Constraints
2 <= nums.length <= 100
.
1 <= nums[i] <= 100
.
nums.length % 2 == 0
.
Clarifying Questions Guidance
Does Alice or Bob remove first? Alice removes first in every round.
Does Alice or Bob append first? Bob appends first in every round.
Does Bob select from the original array before Alice's removal? No; Bob selects a minimum from the remaining elements afterward.
Can equal minimum values occur? Yes; no uniqueness guarantee is given. Removing either equal occurrence gives the same sequence of output values.
Must a game strategy be optimized? No; follow the specified rules and return their result.
C++ Interface
class Solution {
public:
vector<int> numberGame(vector<int>& nums) {
}
};
Reasoning Checkpoints
Preserve both the removal order and the different append order.
Account for duplicate values and every original occurrence.
Use the even-length guarantee so every round has exactly two removals.