Increasing Triplet Subsequence

Medium

Description

Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exist, return false.

Examples

Input:nums = [1,2,3,4,5]
Output:true
Explanation:

Any triplet where i < j < k works.

Input:nums = [5,4,3,2,1]
Output:false
Explanation:

No increasing triplet exists.

Input:nums = [2,1,5,0,4,6]
Output:true
Explanation:

Triplet (1, 4, 5) at indices (1, 4, 5) or (0, 4, 5) works.

Constraints

  • 1 ≤ nums.length ≤ 5 × 10⁵
  • -2³¹ ≤ nums[i] ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!