Write and . Rotate the sequence to start immediately after an index where is minimum. This only permutes the possible starting indices, so it preserves the number of successful shifts. The prefix sums of the rotated sequence are all nonnegative: before wrapping they are differences from the minimum, and after wrapping they have an additional .
We may therefore assume that for all , with and .
For each integer , let be the last index with . Each such height occurs because the prefix sums go from to and every upward step is at most . Since , we have .
Every later prefix sum is greater than . A later value equal to contradicts the choice of . A later value below would force another visit to before reaching , because upward steps cannot skip an integer height. Thus the shift starting after has positive prefix sums before wrapping. After wrapping, its prefix sums have the form
So these starting indices all work.
Conversely, suppose the shift starting after works. Its prefix ending at the original last element has sum , so . No later prefix sum can equal , since that would give a nonempty prefix of the shift with sum zero. Therefore is the last occurrence of its height and equals .
There are exactly successful starting indices.