Skip to the code
cf.
+50 XP

#65 Best Streak With One Skip

hard

A fitness challenge scores each day in nums. A participant picks a run of back-to-back days and may drop at most one day from it (a "skip"). The run must still contain at least one day after the skip.

Write bestWithSkip(nums) that returns the largest total such a run can have.

Example 1

Input: nums = [3,-4,2,-1,5]
Output: 9

Take the whole run and skip -4: 3 + 2 - 1 + 5 = 9.

Example 2

Input: nums = [-3,-1,-4]
Output: -1

Every day is negative and at least one day must stay, so keep just -1.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^4 <= nums[i] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).