Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Check if an array is sorted

Determine whether a list is sorted in non-decreasing order.

Python practice10 minSearching & SortingBeginnerLast updated March 25, 2026

Problem statement

Given a list of comparable values (numbers), determine whether the list is sorted in non-decreasing (ascending) order. Return True for empty lists and single-element lists. The function should run in O(n) time and O(1) extra space.

Task

Implement a function that returns True if the given list is sorted in non-decreasing order, otherwise False.

Examples

Simple sorted list

Input

is_sorted([1, 2, 2, 3])

Output

True

Each item is less than or equal to the next, so the list is sorted.

Input format

A single Python list: is_sorted(arr)

Output format

A boolean value (True or False) indicating whether arr is sorted in non-decreasing order.

Constraints

Do not use the built-in sorted() to compare; iterate once and compare neighbors. Works with ints and floats.

Samples

Sample 1

Input

is_sorted([])

Output

True

Empty list is considered sorted.