Increasing Triplet Subsequence

Given an integer array nums, determine whether there exists a subsequence of length three such that the three values are strictly increasing. Pattern focus: LIS. Identify the smallest possible first, second, and third values while scanning once from left to right.

Input Format

nums = array of integers

Output Format

true if an increasing subsequence of length 3 exists, otherwise false

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

Examples

Example 1:

Input:

nums = [1,2,3,4,5]

Output:

true

Explanation:

The subsequence 1, 2, 3 is strictly increasing.

Example 2:

Input:

nums = [5,4,3,2,1]

Output:

false

Explanation:

There is no increasing subsequence of length 3.

Example 3:

Input:

nums = [2,1,5,0,4,6]

Output:

true

Explanation:

The subsequence 1, 4, 6 is strictly increasing.

Loading...
Increasing Triplet Subsequence - Dp Advanced