Click4Ai

10.

Easy

Write a function is_sorted(arr) that checks whether an array is sorted in non-decreasing (ascending) order. Return True or False.

Example:

Input: arr = [1, 2, 3, 4, 5]

Output: True

Input: arr = [1, 3, 2, 4, 5]

Output: False

Constraints:

  • Array length: 1 <= len(arr) <= 1000
  • A single-element array is always sorted
  • Test Cases

    Test Case 1
    Input: [1, 2, 3, 4, 5]
    Expected: True
    Test Case 2
    Input: [1, 3, 2, 4, 5]
    Expected: False
    Test Case 3
    Input: [5, 4, 3, 2, 1]
    Expected: False
    + 2 hidden test cases