Suppose we have a list of numbers called nums and that is sorted in non-decreasing order, we have to check whether it can be split into any number of subsequences such that each subsequence has at minimum length of 3 and that is consecutively increasing.
So, if the input is like nums = [2, 3, 4, 4, 5, 6, 7], then the output will be True, as we can split the list to [2, 3, 4] and [4, 5, 6, 7].
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
from collections import Counter class Solution: def solve(self, nums): count = Counter(nums) starts =  ends =  for x in sorted(count): if count[x] > count[x - 1]: starts.extend([x] * (count[x] - count[x - 1])) if count[x] > count[x + 1]: ends.extend([x] * (count[x] - count[x + 1])) return all(s + 2 <= e for s, e in zip(starts, ends)) ob = Solution() nums = [2, 3, 4, 4, 5, 6, 7] print(ob.solve(nums))
[6, 7, 5, 10, 13], 2