Leetcode Problem 334. Increasing Triplet Subsequence

334. Increasing Triplet Subsequence

Leetcode Solutions

Key approach of the solution.

  1. Initialize first_num and second_num to a very large number (e.g., float('inf') in Python).
  2. Iterate through each element n in the array nums.
  3. If n is less than first_num, set first_num to n.
  4. Else if n is greater than first_num and less than second_num, set second_num to n.
  5. Else if n is greater than second_num, return true as we have found the triplet.
  6. If the loop completes without returning true, return false as no triplet exists.
UML Thumbnail

Alternative approach using sorting and binary search

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...