# 334. Increasing Triplet Subsequence

#### Medium

***

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`.

&#x20;

**Example 1:**

<pre><code>Input: nums = [1,2,3,4,5]
<strong>Output:
</strong> true
<strong>Explanation:
</strong> Any triplet where i &#x3C; j &#x3C; k is valid.
</code></pre>

**Example 2:**

<pre><code>Input: nums = [5,4,3,2,1]
<strong>Output:
</strong> false
<strong>Explanation:
</strong> No triplet exists.
</code></pre>

**Example 3:**

<pre><code>Input: nums = [2,1,5,0,4,6]
<strong>Output:
</strong> true
<strong>Explanation:
</strong> The triplet (3, 4, 5) is valid because nums[3] == 0 &#x3C; nums[4] == 4 &#x3C; nums[5] == 6.
</code></pre>

&#x20;

**Constraints:**

* `1 <= nums.length <= 5 * 105`
* `-231 <= nums[i] <= 231 - 1`

&#x20;

**Follow up:** Could you implement a solution that runs in `O(n)` time complexity and `O(1)` space complexity?

```python
class Solution:
    def increasingTriplet(self, nums: List[int]) -> bool:
        first = second = float("inf")
        for num in nums:
            if num <= first:
                first = num
            elif num <= second:
                second = num
            else:
                return True
        return False
```
