Problem
You start with power and a score of 0. Each token in tokens can be played at most once, in any order, in one of two ways:
- Face up: if your power is at least tokens[i], lose tokens[i] power and gain 1 score.
- Face down: if your score is at least 1, gain tokens[i] power and lose 1 score.
You do not have to play every token. Return the largest score you can reach at any point.
Example 1
- Input
- tokens = [100], power = 50
- Output
- 0
Example 2
- Input
- tokens = [200, 100], power = 150
- Output
- 1
Example 3
- Input
- tokens = [100, 200, 300, 400], power = 200
- Output
- 2
Constraints
0 <= tokens.length <= 10000 <= tokens[i], power < 10^4