2786. Visit Array Positions to Maximize Score
You are given a 0-indexed integer array
numsand a positive integerx.You are initially at position
0in the array and you can visit other positions according to the following rules:
- If you are currently in position
i, then you can move to any positionjsuch thati < j.- For each position
ithat you visit, you get a score ofnums[i].- If you move from a position
ito a positionjand the parities ofnums[i]andnums[j]differ, then you lose a score ofx.Return the maximum total score you can get.
Note that initially you have
nums[0]points.
1 | class Solution { |