Min Max Game — LeetCode 2293 Python Solution
EasyArraySimulation
- Problem
- #2293
- 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
Python
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
| Measure | Complexity |
|---|---|
| Time | O(n), where n is the length of the array \textit{nums} |
| Space | O(1) auxiliary |
Related problems
LeetCode 2303Calculate Amount Paid in TaxesEasyLeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMedium
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.