Check if a rotated array was originally sorted - MATLAB Cody - MATLAB Central

Problem 43072. Check if a rotated array was originally sorted

Difficulty:Rate

Suppose a sorted array is rotated at some pivot unknown to you. For example, [0 1 2 4 5 6 7] might become [5 6 7 0 1 2 4].

Given a rotated array, find out if it was originally sorted. Your function will return true for this array: [4 5 6 7 0 1 2]. But it will return false for [2 5 6 8 0 1 3], because its original array, i.e., [0 1 3 2 5 6 8], was not sorted.

Solution Stats

67.19% Correct | 32.81% Incorrect
Last Solution submitted on Jun 01, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
1
3

Problem Recent Solvers75

Suggested Problems

More from this Author3

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!