Gamified challenge · Fixed sliding window
tips[i] is what shift i earns in tips (a negative number is a fine for a broken plate). You may work exactly k consecutive shifts, with 1 ≤ k ≤ len(tips).
Write bestShift(tips, k) that returns the largest total any run of k consecutive shifts can earn. For tips = [4, 2, 7, 1, 8, 3] and k = 2 the runs earn 6, 9, 8, 9 and 11, so the answer is 11.
Re-adding every window works, but try to move from one window to the next with one addition and one subtraction.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google