Min Max Game - Problem

Imagine you're running a tournament elimination system where competitors face off in pairs, but with a twist! In each round, some pairs compete for the minimum score (even positions) while others compete for the maximum score (odd positions).

You are given a 0-indexed integer array nums whose length is a power of 2. Apply this special tournament algorithm:

  1. If only 1 number remains, that's your winner!
  2. Otherwise, create a new array with half the length
  3. For even indices i: take the min(nums[2*i], nums[2*i+1])
  4. For odd indices i: take the max(nums[2*i], nums[2*i+1])
  5. Repeat until one number survives

Goal: Return the final survivor number after all tournament rounds.

Input & Output

example_1.py โ€” Python
$ Input: [1,3,5,2,4,7,2,3]
โ€บ Output: 1
๐Ÿ’ก Note: Round 1: [min(1,3)=1, max(5,2)=5, min(4,7)=4, max(2,3)=3] = [1,5,4,3]. Round 2: [min(1,5)=1, max(4,3)=4] = [1,4]. Round 3: [min(1,4)=1] = [1]. Answer: 1
example_2.py โ€” Python
$ Input: [3]
โ€บ Output: 3
๐Ÿ’ก Note: Array already has length 1, so we return the only element: 3
example_3.py โ€” Python
$ Input: [70,38,21,22]
โ€บ Output: 22
๐Ÿ’ก Note: Round 1: [min(70,38)=38, max(21,22)=22] = [38,22]. Round 2: [min(38,22)=22] = [22]. Answer: 22

Constraints

  • 1 โ‰ค nums.length โ‰ค 1024
  • nums.length is a power of 2
  • 1 โ‰ค nums[i] โ‰ค 109

Visualization

Tap to expand
๐Ÿ† Min-Max Tournament Championship13MIN โ†’ 152MAX โ†’ 547MIN โ†’ 423MAX โ†’ 315MIN โ†’ 143MAX โ†’ 414MIN โ†’ 11CHAMPION!๐ŸŽฏ Each round eliminates half the competitors using alternating min/max rules
Understanding the Visualization
1
Setup Tournament
Arrange all numbers in pairs for the first round
2
Apply Rules
Even positions take minimum, odd positions take maximum
3
Advance Winners
Winners form the next round's competitors
4
Repeat Until One
Continue until only one champion remains
Key Takeaway
๐ŸŽฏ Key Insight: This tournament simulation demonstrates how alternating competitive rules (min vs max) create a unique elimination pattern that always converges to a single winner in log(n) rounds.
Asked in
Amazon 15 Google 8 Microsoft 5 Apple 3
28.0K Views
Medium Frequency
~8 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen