Help me understand following q (cpp soln must)

You are given a sorted but rotated array. You need to fine the index of the pivot element of the array where pivot is that element in the array which is greater than its next element and divides the array into two monotonically increasing halves.
Input Format

The first line denotes N - the size of the array. The following N lines each denote the numbers in the array.
Constraints

Output Format

Output the index of the pivot of the array.
Sample Input

5
4
5
1
2
3

Sample Output

1

Explanation

Here, 5 is the pivot element. Thus the output is 1 which is 5’s index.

Here’s the code for the same, just checking in the first sorted half if element is there or not. If not present then checking for next sorted half in the array. I would suggest you to dry run it for different inputs. You will get the intuition.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.