FastPrepMinimum Right Rotations to Strictly Descending

Minimum Right Rotations to Strictly Descending

ZipRecruiter logoZipRecruiter● EasyNEW GRADFULLTIMEOA
Learn

Problem statement

Return the minimum number of cyclic right rotations that makes values strictly descending. Return 0 when it already qualifies and -1 when no rotation qualifies.

Function

rightRotationsToDescending(values: int[]) → int

Examples

Example 1

values = [4,3,2,1,5]return = 1

One right rotation moves five to the front.

Example 2

values = [5,4,3]return = 0

A qualifying array needs zero rotations.

Constraints

  • 0 <= values.length <= 100000
  • -1000000000 <= values[i] <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int rightRotationsToDescending(int[] values) {
    // Write your code here.
}
values[4,3,2,1,5]
expected1
Checking account…