Reported October 2026
Capital Onearray

First Value Below Both Neighbors

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

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

Strip the wording off this Capital One question, reported in October 2026, and it's one linear scan with a neighbor check. Find the first interior element that's strictly smaller than both neighbors, return its value, else -1. It looks like a gimme, and it mostly is. The points get lost on edge cases: equal neighbors, endpoints, and returning the value instead of the index. If you've got the OA coming up and your head goes blank under the timer, StealthCoder runs invisibly on your desktop as a safety net and gives you the solution in real time. Most people won't need it here, but a trivial problem is where careless mistakes happen.

The problem

Given an integer array nums, inspect its interior elements from left to right. Return the value of the first element whose immediate left and right neighbors are both strictly larger.
Return -1 when no such interior element exists. The first and last elements are not eligible because they do not have two adjacent neighbors.

Function
firstValleyValue(nums: int[]) → int

Examples
Example 1
nums = [8,3,5,2,4]
return = 3
The value 3 is below both 8 and 5. Although 2 is also below both neighbors, it appears later.
Example 2
nums = [1,2,3]
return = -1
The only interior value is not below either neighbor.
Example 3
nums = [5,1,1,5]
return = -1
Equal adjacent values do not satisfy the strict comparison.

Constraints
3 <= nums.length <= 10^5.
0 <= nums[i] <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that there's no trick. Loop i from 1 to n-2 and check nums[i] < nums[i-1] and nums[i] < nums[i+1]. Return nums[i] the moment both hold. If the loop ends, return -1. That's O(n) time and O(1) space, which is plenty for 10^5 elements. The pitfalls are small but real. Use strict less-than, because example 3 with [5,1,1,5] must return -1 since equal neighbors don't count. Don't start at index 0 or run to the last index, or you'll read out of bounds. Return the value, not the index. Don't scan for the smallest valley, because example 1 wants 3, not 2. Return on the first hit. If you blank on any of this during the real Capital One OA, StealthCoder is the hedge that stays hidden from the proctor while you recover and submit clean code.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill First Value Below Both Neighbors 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Capital One reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

First Value Below Both Neighbors FAQ

How hard is the First Value Below Both Neighbors problem really?+

Easy. It's a single pass with a two-comparison check at each interior index. The difficulty is only in the details: strict inequality, skipping the endpoints, and returning the value instead of the index. If you can write a for loop, you can solve it in a couple of minutes.

What's the pattern for this Capital One OA question?+

It's a plain array scan, sometimes called a local minimum check. You compare each interior element to its left and right neighbors. There's no sorting, hashing, or dynamic programming needed. Early return on the first match handles the 'first' requirement.

What edge cases should I test before submitting?+

Test [1,2,3] for -1, [5,1,1,5] for -1 because of equal values, and [8,3,5,2,4] for 3, not 2. Also try a length-3 array like [4,1,4], which should return 1. And check a case where the valley is the last interior index, to confirm your loop bound is right.

Do I need anything better than O(n)?+

No. You have to look at elements until you find a match, and with n up to 10^5 a linear scan is fast. Binary search doesn't apply because the array isn't sorted or guaranteed to have a valley. Keep space at O(1) with no extra arrays.

How do I prepare for this in 48 hours?+

Write this one from memory once, then do two or three similar neighbor-comparison array problems like peaks or local extrema. Focus on loop bounds and strict versus non-strict comparisons. Spend the rest of your time on harder problems, since an OA usually has more than one question.

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

OA at Capital One?
Invisible during screen share
Get it