2786. Visit Array Positions to Maximize Score
You are given a 0-indexed integer array
nums
and a positive integerx
.You are initially at position
0
in 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 positionj
such thati < j
.- For each position
i
that you visit, you get a score ofnums[i]
.- If you move from a position
i
to a positionj
and 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 { |