LeetCode Problem - Link
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.
Example 1:
Input: nums = [1,2,3,4,10]
Output: false
Explanation:
Alice cannot win by choosing either single-digit or double-digit numbers.
Sequential Solution
Probably the easiest problem I have faced so far on LeetCode. Here goes
/** * @param {number[]} nums * @return {boolean} */ var canAliceWin = function (nums) { var oneDigitSum = 0; var twoDigitSum = 0; for (var i = 0; i < nums.length; i++) { var num = nums[i] if (num >= 10) { twoDigitSum += num } else { oneDigitSum += num } } // if they dont equal, then its true return oneDigitSum !== twoDigitSum };