FastPrepLeft Rotation to a Strictly Increasing Array

Left Rotation to a Strictly Increasing Array

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Given a nonempty integer array numbers, return how many cyclic left shifts make it strictly increasing.

If no cyclic left rotation works, return -1. Return the unique valid shift when one exists.

Function

rotationToIncreasing(numbers: int[]) → int

Examples

Example 1

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

Rotating left by three produces [1,2,3,4,5].

Example 2

numbers = [1,2,3]return = 0

The array is already strictly increasing.

Constraints

  • 1 <= numbers.length <= 100000

More ZipRecruiter problems

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