Skip to main content
Back to problems
#334
Medium Algorithms

Increasing triplet subsequence

Array Greedy
39.2% acceptance
Jan 12, 2026
8827
691
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 exists, return false.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn increasing_triplet(nums: Vec<i32>) -> bool {
    let mut first = i32::MAX;
    let mut second = i32::MAX;
    
    for &num in &nums {
      if num <= first {
        first = num;
      } else if num <= second {
        second = num;
      } else {
        return true;
      }
    }
    
    false
  }
}