FastPrepAlternate through Forest Positions until 100
Problems/Alternate through Forest Positions until 100

Alternate through Forest Positions until 100

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report describes forest values, a starting Bird index, alternating right and left collection until at least 100, returned indices, and the example [0,0,0,20,50,0,0,30] giving [4,7,3]. We supplied the nearest positive positions, skipping zeros, what happens when one side runs out, and early exhaustion. Our version is about 84% the same as the reported question.

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 <= 100000
  • 0 <= forest[i] <= 100
  • 0 <= 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

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[] forestVisitOrder(int[] forest, int start) {
        // Write your code here.
    }

}
Checking account…