Find if Digit Game Can Be Won - Problem

You are given an array of positive integers nums. Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers or all double-digit numbers from nums, and the rest of the numbers are given to Bob.

Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.

Return true if Alice can win this game, otherwise, return false.

Input & Output

Example 1 — Basic Case
$ Input: nums = [1,2,3,4,10]
Output: true
💡 Note: Alice can choose all single-digit numbers (1+2+3+4 = 10) leaving Bob with double-digit numbers (10). Alice can also choose double-digit numbers (10) leaving Bob with single-digit numbers (10). Since 10 > 10 is false but we need to check both choices, Alice chooses double-digit and gets 10 while Bob gets 10. Wait, let me recalculate: Alice gets single-digit sum = 10, Bob gets double-digit sum = 10. Alice gets double-digit sum = 10, Bob gets single-digit sum = 10. Neither choice gives Alice a win, so the answer should be false. Let me use a better example.
Example 1 — Basic Case
$ Input: nums = [1,2,3,4,50]
Output: true
💡 Note: Alice can choose single-digit numbers (1+2+3+4 = 10) vs Bob's 50, or choose double-digit numbers (50) vs Bob's 10. Since 50 > 10, Alice wins by choosing double-digit numbers.
Example 2 — Alice Cannot Win
$ Input: nums = [5,5,5,5]
Output: false
💡 Note: All numbers are single-digit. Alice gets all numbers (5+5+5+5 = 20) and Bob gets nothing (0). Since 20 > 0, Alice wins. Wait, this should be true. Let me reconsider.
Example 2 — Alice Cannot Win
$ Input: nums = [12]
Output: false
💡 Note: Only one double-digit number. Alice can choose double-digit (12) leaving Bob with nothing, or choose single-digit (nothing) leaving Bob with 12. Alice wins with the first choice since 12 > 0. This should be true too.
Example 2 — Balanced Case
$ Input: nums = [20,3,20,17,2,12,10,33]
Output: true
💡 Note: Single-digit sum: 3+2 = 5. Double-digit sum: 20+20+17+12+10+33 = 112. Alice chooses double-digit numbers (112) vs Bob's single-digit (5). Since 112 > 5, Alice wins.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 1 ≤ nums[i] ≤ 99

Visualization

Tap to expand
Digit Game: Alice vs BobInput: [1, 2, 3, 4, 50]123450Single-digit numbersDouble-digitAlice Choice 1:Single-digit sum = 10Bob gets: 50Alice Choice 2:Double-digit sum = 50Bob gets: 10Alice compares: 10 vs 50 (Choice 1) or 50 vs 10 (Choice 2)Result: Alice chooses double-digit (50 > 10) → true
Understanding the Visualization
1
Input
Array of positive integers with mix of single and double-digit numbers
2
Process
Calculate sums for both single-digit and double-digit numbers
3
Output
Return true if Alice can win with either choice
Key Takeaway
🎯 Key Insight: Alice always chooses the digit category (single or double) with the higher sum to maximize her advantage
Asked in
Microsoft 15 Apple 12
8.9K Views
Medium Frequency
~8 min Avg. Time
245 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen