Editor

Already in Order?

#501 · Lists · Beginner · 25 XP · about 4 min

Write is_sorted(nums) that returns True if every number in the list is at least as big as the number before it, and False otherwise. Equal neighbors are fine: [1, 2, 2, 3] is sorted.

An empty list, and a list with one number, count as sorted. Try it without calling sorted(): one pass over the list is enough.

Examples

is_sorted([1, 2, 2, 5])  # returns True
is_sorted([3, 1, 2])     # returns False
is_sorted([])            # returns True

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.