Practice Minimum Levels to Gain More Points
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a binary array possible of length n. Alice and Bob are playing a game that consists of n levels. Some of the levels in the game are impossible to clear while others can always be cleared. In particular, if possible[i] == 0, then the ith level is impossible to clear for both the players. A player gains 1 point on clearing a level and loses 1 point if the player fails to clear it. At the start of the game, Alice will play some levels in the given order starting from the 0th level, after which Bob will play for the rest of the levels. Alice wants to know the minimum number of levels she should play to gain more points than Bob, if both players play optimally to maximize their points. Return the minimum number of levels Alice should play to gain more points. If this is not possible, return -1. Note that each player must play at least 1 level.
Source: Minimum Levels to Gain More Points on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
possible = [1,0,1,0]
1
# Example 2
possible = [1,1,1,1,1]
3
# Example 3
possible = [0,0]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Levels to Gain More Points.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.