EasyNo. 2293
Min Max Game — LeetCode 2293 Python Solution
- Topics
- Array, Simulation
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given a 0-indexed integer array nums whose length is a power of 2. Apply the following algorithm on nums: Let n be the length of nums.
Example
- Input
- nums = [1,3,5,2,4,8,2,2]
- Output
- 1
- Explanation
- The following arrays are the results of applying the algorithm repeatedly.
Python solution
class Solution:
def minMaxGame(self, nums: List[int]) -> int:
n = len(nums)
while n > 1:
n >>= 1
for i in range(n):
a, b = nums[i << 1], nums[i << 1 | 1]
nums[i] = min(a, b) if i % 2 == 0 else max(a, b)
return nums[0]Complexity
- Time
- O(n)where n is the length of the array nums
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2303 | Calculate Amount Paid in Taxes | Easy |
| 0495 | Teemo Attacking | Easy |
| 0985 | Sum of Even Numbers After Queries | Medium |
| 1389 | Create Target Array in the Given Order | Easy |
| 1409 | Queries on a Permutation With Key | Medium |
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Medium |
Frequently asked questions
- How hard is LeetCode 2293. Min Max Game?
LeetCode 2293. Min Max Game is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2293. Min Max Game?
The Python solution on this page runs in O(n), where n is the length of the array \textit{nums}.
- What is the space complexity of LeetCode 2293. Min Max Game?
The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2293. Min Max Game cover?
LeetCode 2293. Min Max Game is tagged Array and Simulation on LeetCode.