Skip to content
Discussion options

You must be logged in to vote

We need to determine if the given array can be obtained by rotating a sorted array in non-decreasing order. Here's a step-by-step approach to achieve this:

  1. Check if the array is already sorted: If the array is already sorted, it means it can be rotated 0 positions to get the same array, so we should return true.

  2. Find the pivot point: The pivot point is where the order drops, i.e., where nums[i] > nums[i+1]. This pivot point indicates the rotation point.

  3. Check the order: After finding the pivot, we need to ensure that the array is sorted in non-decreasing order before and after the pivot.

  4. Handle duplicates: If there are duplicates, we need to ensure that the pivot is the only point…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Feb 2, 2025
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Feb 2, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants