Three on the rise
Reported in interviews at (where)
Does the list nums hold three positions i < j < k with nums[i] < nums[j] < nums[k]? The three need not sit next to each other.
Return true if they exist and false if not, in one pass and without an extra list.
- Input
nums = [5,1,4,2,6]- Output
true
1, 4, 6 at positions 1, 2 and 4.
- Input
nums = [9,7,7,3]- Output
false
The list never rises.
- Input
nums = [2,9,1,3]- Output
false
2 < 9 and 1 < 3, but no three positions rise in order.
Limits
1 <= nums.length <= 100000-2^31 <= nums[i] <= 2^31 - 1
Hints
Hint 1
Keep the smallest value seen, and the smallest value that has something smaller before it.
Hint 2
A number bigger than both finishes a triple.
Where this was reported
- Flipkart, SDE-1 interview (GeeksforGeeks)
- KLA Corporation, Internship online assessment, 2021 (LeetCode)
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.
