#3847

Find the Score Difference in a Game

medium · 71.9% accepted · 43 likes · top 81%

array · simulation

Description

You are given an integer array nums, where nums[i] represents the points scored in the ith game.

There are exactly two players. Initially, the first player is active and the second player is inactive.

The following rules apply sequentially for each game i:

- If nums[i] is odd, the active and inactive players swap roles.

- In every 6th game (that is, game indices 5, 11, 17, ...), the active and inactive players swap roles.

- The active player plays the ith game and gains nums[i] points.

Return the score difference, defined as the first player's total score minus the second player's total score.

Solution