Sum Strict Local Maxima
Updated
Problem statement
You are given an integer array nums.
An element at index i is a strict local maximum when it has two neighbors and is greater than both of them: nums[i] > nums[i - 1] and nums[i] > nums[i + 1].
Return the sum of all strict local maxima. The first and last elements are never considered because they do not have two neighbors.
Function
sumStrictLocalMaxima(nums: int[]) → longExamples
Example 1
nums = [1,5,2,4,3]return = 95 is greater than 1 and 2, and 4 is greater than 2 and 3. Their sum is 9.
Example 2
nums = [5,1,4]return = 0The only eligible element is 1, which is smaller than both neighbors. The endpoints are not eligible.
Constraints
3 <= nums.length <= 105-109 <= nums[i] <= 109- The answer fits in a signed 64-bit integer.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- Build the Task HierarchyPendo · OA
- Closest NumbersHeadlands Technologies · OAHeadlands Technologies interview questions
- Count Numbers Not Equal to the First TwoAirbnb · OAAirbnb interview questions
- Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- REST API: Country CodesHackerRank · OAHackerRank interview questions
- Macaron Order with Set DiscountsShopify · OAShopify interview questions
- Lowest Number in an Open RangeCapital One · OACapital One interview questions
- Missing IntervalsIBM · OAIBM interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions