Ctrl K

A Rising Trio

Medium
You are given an integer array values. Check whether you can pick three elements at indices i < j < k whose values strictly increase: values[i] < values[j] < values[k]. The elements don't have to be adjacent. Return True if such a trio exists and False otherwise. Try to do it in a single pass with O(1) extra memory.
Example 1
values=[7, 3, 8, 1, 2, 5] → True

Indices 3, 4, 5 work, for example: 1 < 2 < 5.

Example 2
values=[4, 4, 4, 4] → False

Equal values do not count as rising.

Example 3
values=[9, 2, 10, 1, 3] → False

There are rising pairs (2 < 10, 1 < 3), but no third element extends any of them.

Constraints
  • 1 ≤ len(values) ≤ 5 · 10⁵
  • -2³¹ ≤ values[i] ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Boards Holding Water MediumFewest Jumps to the End MediumReach the Last Cell MediumAs Many Trades as You Like MediumWhere to Start the Lap Medium
loading Python…
Input
values=[7, 3, 8, 1, 2, 5]
Expected
True

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