- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Increasing Triplet Subsequence in Python
Suppose there is an unsorted array. We have to check whether an increasing subsequence of length 3 exists or not in that array.
Formally the function should −
- Return true if there exists i, j, k
- such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.
To solve this, we will follow these steps −
- small := infinity, big := infinity
- for each element i in array
- if i <= small, then small := i, otherwise when i <= big, then big := i, otherwise return true
- return false
Let us see the following implementation to get better understanding −
Example
class Solution(object): def increasingTriplet(self, nums): small,big = 100000000000000000000,100000000000000000000 for i in nums: if i <= small: small = i elif i<=big: big = i else : return True return False ob1 = Solution() print(ob1.increasingTriplet([5,3,8,2,7,9,4]))
Input
[5,3,8,2,7,9,4]
Output
True
- Related Articles
- Longest Increasing Subsequence in Python
- Longest Increasing Subsequence
- Checking for increasing triplet in JavaScript
- Program to find length of longest increasing subsequence in Python
- Longest Continuous Increasing Subsequence in C++
- Maximum Sum Increasing Subsequence\n
- Program to find length of longest circular increasing subsequence in python
- Number of Longest Increasing Subsequence in C++
- Java Program for Longest Increasing Subsequence
- Maximum product of an increasing subsequence in C++
- Maximum Sum Increasing Subsequence | DP-14 in C++
- Maximum product of an increasing subsequence in C++ Program
- Maximum Sum Increasing Subsequence using DP in C++ program
- Maximum product of a triplet (subsequence of size 3) in array in C++
- Maximum Sum Increasing Subsequence using Binary Indexed Tree in C++

Advertisements