Min Max Game (Optimal)
IntuitionApproachComplexity
Time complexity:
O(n log n)
Space complexity:
O(1)Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n log n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)

# Code
```cpp []
class Solution {
public:
    int minMaxGame(vector<int>& nums) {
        while(nums.size()>1)
        {
            int n=nums.size()/2;
            for(int i=0;i<n;i++)
            {
                if(i%2==0)
                {
                    nums[i]=min(nums[2*i],nums[2*i+1]);
                }
                else
                {
                    nums[i]=max(nums[2*i],nums[2*i+1]);
                }
            }
            nums.resize(n);
        }
        return nums[0];
    }
};
```
['Array', 'Simulation', 'C++']