#2974
Easy Algorithms Minimum number game
Array Sorting Heap (Priority Queue) Simulation
85.4% acceptance
Feb 25, 2026
341
23
You are given a 0-indexed integer array nums of even length. Alice and Bob play a game where each round: Alice removes minimum, then Bob removes minimum. Bob appends first, then Alice appends.
Return the resulting array arr.
Solution
Rust
Time O(n log n)
Space O(n)
impl Solution {
pub fn number_game(mut nums: Vec<i32>) -> Vec<i32> {
nums.sort_unstable();
let n = nums.len();
let mut result = Vec::with_capacity(n);
for i in (0..n).step_by(2) {
// Alice removes nums[i], Bob removes nums[i+1]
// Bob appends first, then Alice
result.push(nums[i + 1]);
result.push(nums[i]);
}
result
}
}