Suppose we have a list of numbers; we have to check whether the list is strictly increasing or strictly decreasing.
So, if the input is like nums = [10, 12, 23, 34, 55], then the output will be True, as all elements are distinct and each element is larger than the previous one, so this is strictly increasing.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, nums): if len(nums) <= 2: return True if len(set(nums)) != len(nums): return False ordered = sorted(nums) return nums == ordered or nums == ordered[::-1] ob = Solution() print(ob.solve([10, 12, 23, 34, 55]))
[10, 12, 23, 34, 55]
True