FastPrep🦉 Collect Sticks
Problems/🦉 Collect Sticks

🦉 Collect Sticks

Instacart logoInstacart● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array forest and the bird's starting position bird.

forest[i] represents the length of the stick at position i.

If forest[i] == 0, it means there is no stick at position i.

The bird's starting position bird will always be an index where there is no stick (forest[bird] == 0).

The bird follows this process:

  • Starting from the initial position, the bird flies right until it finds the first stick.
  • It picks up the stick and brings it back to the starting position.
  • Next, the bird flies left until it finds the next stick.
  • It picks up that stick and brings it back to the starting position.
  • The bird repeats this process: alternating right and left until it collects sticks with a total length of at least 100.

You need to output the indices of the sticks that the bird picks up, in the order they are collected.

Note:

  • There will always be a stick available in the current flying direction.
  • No edge cases like "flying right and finding no sticks" will occur.

Function

collectSticks(forest: int[], bird: int) → List<Integer>

Examples

Example 1

forest = [0, 50, 0, 30, 0, 25]bird = 2return = [3, 1, 5]

The bird first flies right to the nearest stick, then left to the nearest stick on that side, and keeps alternating until the total collected length is large enough. The output lists the picked positions in that order.

Constraints

  • 🦉

More Instacart interview questions

  • Find First and Last Position in a Sorted ArrayPHONE SCREEN · Seen Nov 2026
  • Squares of a Sorted ArrayPHONE SCREEN · Seen Nov 2026
  • Evaluate Formulas with Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Process Shopping Records, Promotions, and Display OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Product Total With the Cheapest PromotionONSITE INTERVIEW · Seen Sep 2026
  • Sort Products by Aisle With Frozen Items LastONSITE INTERVIEW · Seen Sep 2026
  • Timed Task ManagementONSITE INTERVIEW · Seen Sep 2026
  • Worker Management with Promotions and Double-Paid TimeONSITE INTERVIEW · Seen Sep 2026
  • Balloon Color PairsOA · Seen Mar 2025
  • Bubble Popping GameOA · Seen Mar 2025

Similar questions at other companies

  • Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • 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
  • Lift Total TravelInfosys · OAInfosys 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

Instacart interview experiences

  • Instacart OA · 2026
All Instacart interview questionsSee Instacart hiring insights
Saved
class Solution {
    public List<Integer> collectSticks(int[] forest, int bird) {
      // write your code here
    }

}
Checking account…