Problem · Array
Score Difference
Learn this problemProblem statement
Two players take turns removing numbers from a sequence. Player 1 moves first.
On each turn:
- Remove the first number from the current sequence and add it to the current player's score.
- If the removed number is even, reverse the remaining sequence.
Continue until the sequence is empty. Return Player 1 score - Player 2 score.
Function
scoreDifference(n: int, numSeq: int[]) → intExamples
Example 1
n = 5numSeq = [3, 6, 2, 3, 5]return = 1The removed values are 3, 6, 5, 3, and 2. Player 1 scores 10 and Player 2 scores 9, so the difference is 1.
Constraints
1 ≤ numSeq.length ≤ 2 × 10^5-10^4 ≤ numSeq[i] ≤ 10^4n = numSeq.length
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026