Score Difference When Even Picks Reverse the List
Updated
Problem statement
Alice and Bob play a game with a list of numbers nums. Alice moves first, and then they take turns until the list is empty.
On each turn, the current player removes the first number of the current list and adds it to their own score. If that number is even, the rest of the list is reversed before the next turn. If it is odd, the rest of the list stays as it is. Note that 0 is even.
Both scores start at 0. Return Alice's final score minus Bob's final score.
Function
scoreDifference(nums: int[]) → intExamples
Example 1
nums = [3,4,1,6,5]return = -1Alice takes 3 (odd, nothing changes). Bob takes 4, which is even, so the rest [1, 6, 5] becomes [5, 6, 1]. Alice takes 5. Bob takes 6, which is even, so the rest [1] is reversed and stays [1]. Alice takes 1.
Alice has 3 + 5 + 1 = 9 and Bob has 4 + 6 = 10, so the answer is 9 - 10 = -1.
Example 2
nums = [2,7,9,1]return = 3Alice takes 2, which is even, so [7, 9, 1] becomes [1, 9, 7]. Bob takes 1. Alice takes 9. Bob takes 7.
Alice has 2 + 9 = 11 and Bob has 1 + 7 = 8, so the answer is 3.
Example 3
nums = [5]return = 5Alice takes the only number, 5. Bob takes nothing, so the answer is 5 - 0 = 5.
Constraints
1 <= nums.length <= 10^50 <= nums[i] <= 10^4
More Microsoft Online Assessment questions
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
- Maximum Interactive Team SizeOA · Seen Nov 2026
- Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
- Minimum Cost K-Capable ModelsOA · Seen Nov 2026
- Find Available Meeting RoomsOA · Seen Oct 2026
- Maximum Sum of a K-StarOA · Seen Oct 2026
- Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Collect Branches for a Bird NestVisa · OAVisa interview questions
- Match OutcomesAdobe · OAAdobe interview questions
- Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
- Configuration SystemPostman · OAPostman interview questions
- Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla interview questions
- Merge a 2048 RowPalantir · PHONE SCREENPalantir interview questions
- Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Nested List Iterator with RemoveAirbnb · PHONE SCREENAirbnb interview questions