#3096

Minimum Levels to Gain More Points

expert · 1030 · lc medium +32 · 40.1% accepted · 88 likes · top 19%

Description

Given a binary array possible of n levels, a level is clearable if possible[i] == 1 (yields +1 point) and impossible if possible[i] == 0 (yields -1 point). Alice plays a prefix of levels and Bob plays the rest; each must play at least one level. Return the minimum prefix length Alice needs so her score strictly exceeds Bob's, or -1 if impossible.

Code

1
2
3