Keep Endpoints and Strict Local Maxima
Updated
Problem statement
Return selected values in original order. Always keep the first and last values. Keep an interior value only when it is strictly greater than both immediate neighbors.
An empty array returns empty, and a singleton is returned once.
Function
keepLocalMaxima(values: int[]) → int[]Examples
Example 1
values = [1,2,1]return = [1,2,1]The strict interior peak joins both endpoints.
Example 2
values = [1,2,3]return = [1,3]Only the endpoints remain.
Constraints
0 <= values.length <= 100000-1000000000 <= values[i] <= 1000000000
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Build the Task HierarchyPendo · OA
- Missing IntervalsIBM · OAIBM interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Two SumAmazon · OA · PHONE SCREEN
- Competition Winner and Runner-Up (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Server InvestmentRippling · OARippling interview questions