Skip to the code
+10 XP

#140 Longest Smooth Scroll Stretch

easy

A scroll performance test records how long each frame took, in milliseconds, in frames. A frame is smooth if it took at most budget milliseconds.

Write longestSmooth(frames, budget) that returns the length of the longest run of neighboring frames that are all smooth. Return 0 if no frame is smooth.

Example 1

Input: frames = [12,16,40,10,11,9,16,33], budget = 16
Output: 4

Frames 3 to 6 (10, 11, 9, 16) are all at most 16 ms.

Example 2

Input: frames = [50,60], budget = 16
Output: 0

No frame is smooth.

Constraints

  • 0 <= frames.length <= 200000
  • 1 <= frames[i], budget <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

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