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 −
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
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]))