Tap here to switch tabs
Problem
Submissions

Problem: Visit Array Positions to Maximize Score

Try to solve the Visit Array Positions to Maximize Score problem.

Statement

You are given an integer array nums and an integer x.

You start at index 00 of the array and can visit a sequence of indices with strictly increasing values, starting at index 00.

When moving from index i to index j (where i < j), you add nums[j] to your total score. However, if nums[i] and nums[j] have different parities (one is odd and the other is even), you must subtract x from your score as a penalty.

Initially, your score is equal to nums[0].

Return the maximum score you can achieve by choosing an optimal sequence of visited indices.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i], x ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Visit Array Positions to Maximize Score

Try to solve the Visit Array Positions to Maximize Score problem.

Statement

You are given an integer array nums and an integer x.

You start at index 00 of the array and can visit a sequence of indices with strictly increasing values, starting at index 00.

When moving from index i to index j (where i < j), you add nums[j] to your total score. However, if nums[i] and nums[j] have different parities (one is odd and the other is even), you must subtract x from your score as a penalty.

Initially, your score is equal to nums[0].

Return the maximum score you can achieve by choosing an optimal sequence of visited indices.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i], x ≤106\leq 10^6