मुख्य कंटेंट तक स्किप करें
Back to ChallengesCheck if an Array is SortedEasy 10 min

Check if an Array is Sorted

Given an array of size n, write a program to check if the given array is sorted in strictly increasing order or not.

Return true if it is, otherwise false.

Examples

Input: arr = [10, 20, 30, 40, 50]
Output: true
The array is strictly increasing.
Input: arr = [10, 20, 30, 30, 50]
Output: false
It is not strictly increasing because 30 appears twice.

Constraints

  • 1 <= arr.length <= 10^5
  • -10^9 <= arr[i] <= 10^9

Complexity Analysis

Time
O(N)
iterating through the array once.
Space
O(1)
constant extra space.

Test Cases

#1 Strictly sorted
Input: arr = [10, 20, 30, 40, 50]
Expected: true
#2 Not strictly sorted (duplicates)
Input: arr = [10, 20, 30, 30, 50]
Expected: false
JavaScript
Output
Click "Run Code" to see output here...