- Related Questions & Answers
- Strictly increasing or decreasing array - JavaScript
- Check if list is strictly increasing in Python
- A strictly increasing linked list in Python
- Program to find length of longest strictly increasing then decreasing sublist in Python
- Strictly increasing sequence JavaScript
- Find groups of strictly increasing numbers in a list in Python
- Make Array Strictly Increasing in C++
- Count Strictly Increasing Subarrays in C++
- Program to find length of contiguous strictly increasing sublist in Python
- Find the count of Strictly decreasing Subarrays in C++
- Program to count n digit integers where digits are strictly increasing in Python
- Program to check sublist sum is strictly greater than the total sum of given list Python
- Find Maximum Sum Strictly Increasing Subarray in C++
- Find an element in an array such that elements form a strictly decreasing and increasing sequence in Python
- Program to find minimum number of operations required to make lists strictly Increasing in python

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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 −

- if size of nums <= 2, then
- return True

- if all elements in num is not distinct, then
- return False

- ordered := sort the list nums
- return true when nums is same as ordered or nums is same as ordered in reverse way, otherwise false.

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

Advertisements