FunctionRacerProblemsRace

Sorted and Rotated

EasyArraysPython, JavaScript, TypeScript, Java, C++

Return True if nums could have started as a list sorted in non-decreasing order and then been rotated by some number of positions (possibly 0). A rotation moves some items from the front to the back, keeping their order.

Repeated values are allowed.

Example 1

nums [3,4,5,1,2]
returns true

It is [1, 2, 3, 4, 5] rotated.

Example 2

nums [2,1,3,4]
returns false

No rotation of a sorted list looks like this.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems