Ctrl K

Counting the Longest Rising Selections

Medium
You are given an integer array values. Pick some of its elements, keeping their order from the array (they need not be adjacent), so that every next number is strictly greater than the previous one. Find the greatest possible length of such a selection and return how many rising selections of that length exist. Selections are told apart by the positions they use, not by their values.
Example 1
values=[3, 1, 4, 2, 5] → 3

The greatest length is 3, and there are three such selections: [3, 4, 5], [1, 4, 5] and [1, 2, 5].

Example 2
values=[7, 7, 7] → 3

The growth must be strict, so the longest selection is a single number, and it can be picked in three ways.

Example 3
values=[1, 2, 3] → 1
Constraints
  • 1 ≤ len(values) ≤ 2000
  • -10⁶ ≤ values[i] ≤ 10⁶
  • The answer fits in a 32-bit integer
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSteady Climb or Drop Trios MediumRising Chain With Small Steps HardSquared Variety Total HardSteep Subsequence With the Largest Sum HardRebuild the Line from Height Records Medium
loading Python…
Input
values=[3, 1, 4, 2, 5]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.