Reported October 2023
ZipRecruiterarray

Left Rotation to a Strictly Increasing Array

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The ZipRecruiter OA reported in October 2023 looks like a rotated sorted array problem, and the naive move is to try every rotation and check each one. That's O(n^2) on 100000 elements, and it dies. The real trap is the edge cases: single elements, already-sorted input, and duplicates that break strictness. This is an array problem with a one-pass answer once you see it. If you blank on the counting trick mid-assessment, StealthCoder runs invisibly on your screen and gives you the solution in real time. Here's the script before you need it.

The problem

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

Reported by candidates. Source: FastPrep

Pattern and pitfall

Count the positions i where numbers[i] >= numbers[i+1], wrapping around from the last element to the first. Strictly increasing after rotation means exactly one descent point at most. If the count is 0, the array is already increasing, so return 0. This only happens when n is 1 or the array is sorted with no wrap descent, and note that [1,2,3] wraps 3 to 1, which is one descent, so handle it separately. If the count is exactly 1 at index i, the answer is (i+1) % n, but only if the wrap pair is also fine. Any count above 1 returns -1. The pitfall is using > instead of >=, which lets duplicates through. Another is forgetting n equals 1. StealthCoder is your hedge if the wrap logic slips under time pressure in the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Left Rotation to a Strictly Increasing Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as check if array is sorted and rotated. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Left Rotation to a Strictly Increasing Array FAQ

What's the trick to Left Rotation to a Strictly Increasing Array?+

Count descents in the circular array, meaning positions where a value is greater than or equal to the next one, including last to first. More than one descent means -1. Exactly one means the rotation starts right after it. Zero descents needs special handling for a single element.

How hard is this ZipRecruiter OA question really?+

Easy to medium. The algorithm is a single pass with a counter. The difficulty is the edge cases: length 1, an already sorted array, and duplicates. Candidates who brute force every rotation hit the 100000 length limit and time out.

Why does strictly increasing matter here?+

Equal neighbors count as a violation. If you use > instead of >=, an array like [1,1,2] looks valid when it isn't. Always compare with >= when counting descents, and the duplicate cases resolve themselves.

What should the already sorted case return?+

Return 0, as in the example [1,2,3]. In a circular check, the wrap from last to first counts as the only descent, so treat that case carefully. A sorted array with one descent at the wrap point means zero shifts, not n.

How do I prepare for this in 48 hours?+

Write the circular descent count from memory twice. Then test it on length 1, sorted, reversed, duplicates, and a true rotation like [3,4,5,1,2]. That covers every branch. It's a short problem, so edge case discipline matters more than extra practice.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it