Skip to the code
cf.
+10 XP

#529 Longest Steady Energy Playlist

easy

A music app gives each song in a queue an energy level, stored in order in energy. To build a playlist that never calms down, you may drop songs but not reorder them, and each kept song must have energy greater than or equal to the song before it.

Write longestSteadyPlaylist(energy) that returns the most songs such a playlist can keep.

Example 1

Input: energy = [3,1,2,2,5,4]
Output: 4

1, 2, 2, 5 (or 1, 2, 2, 4). Equal energy is allowed.

Example 2

Input: energy = [9,8,7]
Output: 1

Every song is calmer than the one before it, so only one can stay.

Constraints

  • 1 <= energy.length <= 1000
  • 0 <= energy[i] <= 100
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).