Check if Array Is Sorted and Rotated Problem

Check if Array Is Sorted and Rotated Problem — ExecCode Easy DSA Practice

Solve the Check if Array Is Sorted and Rotated problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Your task is to otherwise, return false. There may be duplicates in the original array. Note: An array A rotated by x positions results in an array B of the same length such that B[i] == A[(i+x) % A.length] for every valid index i.

Examples

Input {"nums": [3, 4, 5, 1, 2]}; Output True. Input {"nums": [2, 1, 3, 4]}; Output False

Constraints

1 <= nums.length <= 100 1 <= nums[i] <= 100

Practice Check if Array Is Sorted and Rotated free on ExecCode. Browse DSA problems, topic map, and placement guides.