Alternate through Forest Positions until 100
Updated
Problem statement
Begin at start, record that index, and collect its nonnegative value. Then alternate searching right and left of start. On each side, choose the nearest not-yet-visited index with a positive value, moving farther outward on later visits to that side; zero positions are skipped.
Stop once the collected sum reaches at least 100. If the requested side has no remaining positive value, continue on the other side. If neither side has one, stop. Return visited indices.
Function
forestVisitOrder(forest: int[], start: int) → int[]Examples
Example 1
forest = [0,0,0,20,50,0,0,30]start = 4return = [4,7,3]Nearest positive right then left positions yield [4,7,3].
Example 2
forest = [100,1]start = 0return = [0]The traversal stops immediately when start reaches the target.
Constraints
1 <= forest.length <= 1000000 <= forest[i] <= 1000 <= start < forest.length
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
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
- Meandering ArrayVerisk · OA
- Interleave Array HalvesAutodesk · OAAutodesk interview questions
- Collect Branches for a Bird NestVisa · OAVisa interview questions
- Maximum Requests in a Time WindowIBM · OAIBM interview questions
- Set IntersectionBlackRock · OABlackRock interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Filter Odds and Reverse EvensUpstart · OAUpstart interview questions
- Score Difference When Even Picks Reverse the ListMicrosoft · OAMicrosoft interview questions