Skip to the code
cf.
+10 XP

#524 Longest Rising Price Sequence

easy

A price chart stores one closing price per day in prices. An analyst wants the longest list of days, in date order but not necessarily next to each other, where every price is strictly higher than the one before.

Write longestRise(prices) that returns the length of that list.

Example 1

Input: prices = [6,2,8,3,9,4,10]
Output: 4

For example 2, 3, 4, 10.

Example 2

Input: prices = [5,5,5]
Output: 1

Equal prices are not a rise, so any single day is the best.

Constraints

  • 1 <= prices.length <= 2500
  • -10000 <= prices[i] <= 10000
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).