Description
You have tokens with values and initial power. You can play a token face up (lose power, gain score) or down (gain power, lose score). Maximize score.
Examples
Input:
tokens = [100], power = 50Output:
0Explanation:
Can't play any token.
Input:
tokens = [], power = 100Output:
0Explanation:
Empty token array means no tokens to play, so maximum score is 0 regardless of initial power.
Input:
tokens = [50, 75, 150, 250], power = 100Output:
2Explanation:
Start with power=100. Play token 50 face-up (power=50, score=1), then token 75 face-up (power=-25, impossible). Instead, play 50 face-up (power=50, score=1), play 250 face-down (power=300, score=0), then play 75 face-up (power=225, score=1) and 150 face-up (power=75, score=2). Maximum achievable score is 2.
Constraints
- •
0 ≤ tokens.length ≤ 1000