Reported September 2023
ZipRecruiterarray

First Strict Local Minimum

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 data structure here is just an array, and that's the whole point. ZipRecruiter reported this OA in September 2023, and it's a first strict local minimum problem: scan once, compare each interior value to its two neighbors, return the first index that beats both. It's short, it's easy to overthink, and the edge cases are where people lose points. If you blank on the loop bounds during the live assessment, StealthCoder runs invisibly on your desktop as a safety net and hands you the solution while you keep typing.

The problem

You are given an integer array numbers. Inspect only positions that have both a left and a right neighbor.
Return the smallest index i such that numbers[i] is strictly less than both numbers[i - 1] and numbers[i + 1]. Return -1 if no such index exists.

Function
firstStrictLocalMinimum(numbers: int[]) → int

Examples
Example 1
numbers = [1,2,3,4]
return = -1
No interior value is smaller than both neighbors.
Example 2
numbers = [1,3,1,2,5]
return = 2
At index 2, value 1 is less than 3 and 2; it is the first qualifying index.

Constraints
0 <= numbers.length <= 100000
-1000000000 <= numbers[i] <= 1000000000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that there's no trick. One pass over the array, starting at index 1 and stopping at length minus 2, since only positions with both neighbors count. At each i, check numbers[i] < numbers[i-1] and numbers[i] < numbers[i+1]. Return i on the first hit, otherwise -1. That's O(n) time and O(1) space. The common pitfalls are off-by-one bounds, using less-than-or-equal instead of strict less-than (so plateaus like [3,1,1,2] correctly return -1), and crashing on empty or tiny arrays. Arrays with fewer than 3 elements must return -1 immediately. Don't sort, don't build a stack, don't reach for a heap. With values up to 1e9 in magnitude, plain integer comparison is safe and no overflow happens because you never do arithmetic. If you freeze on the live OA, StealthCoder can supply the loop so you can spend your attention on edge cases.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill First Strict Local Minimum 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

ZipRecruiter reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

First Strict Local Minimum FAQ

How hard is the First Strict Local Minimum question really?+

It's easy. A single loop with two comparisons solves it. The difficulty is purely in the edge cases: empty arrays, arrays shorter than three elements, and equal neighbors. If you handle those, you're done in a few minutes.

What's the trick to solving it?+

There isn't one beyond careful bounds. Loop i from 1 to n-2, check that numbers[i] is strictly less than both neighbors, and return the first such i. Return -1 if the loop finishes. Early return guarantees you get the smallest index.

Does strictly less matter?+

Yes. Equal neighbors disqualify an index. In [3,1,1,2], neither 1 qualifies because each has an equal neighbor, so the answer is -1. Using less-than-or-equal is the most common wrong answer on this problem.

What about empty or very short arrays?+

Constraints allow length 0, so don't assume data exists. With fewer than 3 elements no index has both neighbors, so return -1. A loop from 1 to n-2 handles this naturally, but add an explicit guard if you want it to be obvious.

How do I prepare for this in 48 hours?+

Write this loop from memory twice, then test it on empty, one element, two elements, a plateau, and a minimum at the first or last interior spot. Then practice similar neighbor-comparison scans like peak finding. Expect the OA to have other, harder questions too.

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