Introduction
LeetCode 1752 – Check if Array Is Sorted and Rotated is a classic array observation problem that tests your understanding of:
- Sorted arrays
- Rotation logic
- Circular traversal
- Edge case handling
- Pattern recognition
At first, many developers overcomplicate this problem by trying to actually rotate arrays and compare them. However, the problem can be solved using a very elegant observation.
This problem is commonly asked in coding interviews because it evaluates:
- Logical thinking
- Array traversal skills
- Optimization ability
- Understanding of rotated arrays
Problem Link
🔗 https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/
Problem Statement
Given an array:
Return:
if the array was originally sorted in non-decreasing order and then rotated some number of times.
Otherwise return:
Duplicates are allowed.
Understanding Rotation
Suppose the original sorted array is:
After rotation:
The array is still almost sorted except for one “breaking point”.
Key Observation
A sorted rotated array can have:
Example:
Breaking point:
Only once.
Invalid Example
Breaking points:
and circularly:
Two breaking points.
So answer is:
Brute Force Approach
Intuition
Try all possible rotations.
For every rotation:
- Rotate array
- Check if sorted
- If any rotation works → return true
Brute Force Algorithm
For every rotation count:
- Create rotated array
- Verify sorted order
If sorted:
Else:
Brute Force Complexity
Time Complexity
because each rotation requires traversal.
Space Complexity
This solution:
- Finds rotation point
- Sorts array
- Rotates sorted array
- Compares with original
This is a valid simulation-based approach.
Java Solution
Optimized Approach (Best Solution)
We do not need:
- Sorting
- Extra arrays
- Rotation simulation
We only count:
Optimized Intuition
For a valid rotated sorted array:
can happen only once.
Also check circular condition:
Optimized Java Solution
Why This Works
If array is sorted and rotated:
- Sequence increases normally
- Only one position breaks order
If more than one break exists:
Dry Run
Input
Step 1
Compare adjacent elements:
Breaking points:
Valid.
Return:
Another Dry Run
Input
Comparisons:
Breaking points:
Invalid.
Return:
Time Complexity Analysis
Time Complexity
because of sorting.
Space Complexity
extra arrays used.
Optimized Approach
Time Complexity
single traversal.
Space Complexity
Comparison of Approaches
| Approach | Time Complexity | Space Complexity |
| Rotation Simulation | O(N log N) | O(N) |
| Decreasing Pair Count | O(N) | O(1) |
Interview Explanation
In interviews, explain:
A sorted rotated array can contain only one position where the order decreases. By counting such breaking points including circular comparison, we can determine validity in linear time.
This demonstrates:
- Pattern recognition
- Circular traversal understanding
- Optimization thinking
Common Mistakes
1. Forgetting Circular Check
Always compare:
using modulo.
2. Actually Rotating Arrays
Unnecessary and inefficient.
3. Using Strictly Increasing Logic
Duplicates are allowed.
So:
is valid.
FAQs
Q1. Why use modulo?
To compare:
circularly.
Q2. Why is only one break allowed?
Because rotation shifts sorted order only once.
Q3. Is sorting required?
No.
Observation-based traversal is enough.
Q4. Is this problem important for interviews?
Yes.
It tests:
- Array logic
- Rotations
- Optimization
- Observation skills
Related Problems
After mastering this problem, practice:
- Search in Rotated Sorted Array
- Find Minimum in Rotated Sorted Array
- Find Minimum in Rotated Sorted Array II
Conclusion
LeetCode 1752 is an excellent observation-based array problem.
It teaches:
- Rotated array logic
- Circular traversal
- Optimization techniques
- Pattern recognition
The key insight is:
A sorted rotated array can have at most one decreasing point.
Once you understand this observation, the optimized solution becomes extremely clean and efficient.





