First Value Below Both Neighbors
Updated
Problem statement
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[]) → intExamples
Example 1
nums = [8,3,5,2,4]return = 3The 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 = -1The only interior value is not below either neighbor.
Example 3
nums = [5,1,1,5]return = -1Equal adjacent values do not satisfy the strict comparison.
Constraints
3 <= nums.length <= 10^5.0 <= nums[i] <= 10^9.
More Capital One Online Assessment questions
- Rank Football TeamsOA · Seen Oct 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
- Arithmetic Triplets After QueriesOA · Seen Oct 2026
- Branch with the Most FilesOA · Seen Oct 2026
- Count One-Swap Number PairsOA · Seen Oct 2026
- Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
- Earliest Meeting Time for All EmployeesOA · Seen Oct 2026
- Earn the Most 🐝OA · Seen Oct 2026
- Sort Adjacent PairsOA · Seen Oct 2026
- Bouncing Diagonal WeightsOA · Seen Oct 2026
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Wind-Blown Leaves Remaining in a GridAbridge · OAAbridge interview questions
- Shell Command Counts with History ReferencesTikTok · OATikTok interview questions
- Count Dropped RequestsJP Morgan Chase · OAJP Morgan Chase interview questions
- Recursively Expanded Shell Command CountsHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions
- Tool ChangerIBM · OAIBM interview questions