Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Sum Game

XPChallenge Points: 20
levelLevel: Medium

Alice and Bob are playing a turn-based game with a numeric string.
You are given a string num of even length, consisting of digits and '?' characters.
The rules are as follows:
1. Players take turns — Alice goes first.
2. On each turn, if there’s still at least one '?', the player:
o Chooses any index i where num[i] == '?'
o Replaces it with a digit from '0' to '9'.
3. The game ends when all '?' are replaced.
Once the game ends:
• Let the first half of num be the left side and the second half be the right side.
• Bob wins if the sum of digits on both halves are equal.
• Alice wins if the sums are not equal.
Both players play optimally.
Your task:
Return true if Alice will win, and false if Bob will win.

Example 1:

Input: num = "5023"

Output: false

Example 2:

Input: num = "25??"

Output: true

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result