Number of rotations (2)

Given a (non empty) circularly sorted vector of integers, find the
number of times the vector is rotated. Assume that there are no
duplicates in the vector and the rotation is in anti-clockwise
direction.

For instance,

[8, 9, 10, 2, 5, 6] is rotated three times,

[9, 10, 2, 5, 6, 8] is rotated two times,

[4, 0, 1, 2, 3] is rotated one time, and

[2, 5, 8, 9, 12] is rotated zero times.

Solve this problem with recursion in logarithmic time, using this header
in C++:

    int number_of_rotations (const vector<int>& v);

or this header in Python:

    number_of_rotations(v: list[int]) -> int

Write the specification of the recursive function that you will need to
write in a comment at the beginning of such function.

Observation

You only need to submit the required procedure; your main program will
be ignored.

Problem information

Author: Unknown
Translator: Jordi Petit

Generation: 2026-01-25T11:19:18.847Z

© Jutge.org, 2006–2026.
https://jutge.org
