334. Increasing Triplet Subsequence
Difficulty: Medium
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
Formally the function should:
Return true if there exists i, j, k
such that arr[i] < arr[j] < arr[k] given 0 ≤ _i_ < _j_ < _k_ ≤ _n_-1 else return false.
Note: Your algorithm should run in O(_n_) time complexity and O(_1_) space complexity.
Example 1:
1 | **Input:** <span id="example-input-1-1" style="display: inline;">[1,2,3,4,5]</span> |
Example 2:
1 | **Input:** <span id="example-input-2-1" style="display: inline;">[5,4,3,2,1]</span> |
Solution
Language: Java
1 | class Solution { |