Skip to content

Practice Bag of Tokens

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#948
LeetCode Problem

Bag of Tokens

Problem Statement

Begin with the given power and score 0. Each token can be used once: playing it face up requires at least its value in power, spends that power and adds one point; playing it face down requires at least one point, spends one point and adds the token's value to power. Tokens may be chosen in any order and some may remain unused. Return the highest score achievable.

Source: Bag of Tokens on LeetCode. Use the original task for its coding environment and submissions.

Examples

# 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 <= 1000
0 <= tokens[i], power < 10^4

Related LeetCode Problems

Practice more problems similar to Bag of Tokens.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.