Problem Β· Array
π¦ Collect Sticks
Learn this problemProblem 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:
You need to output the indices of the sticks that the bird picks up, in the order they are collected.
Note:
Function
collectSticks(forest: int[], bird: int) β List<Integer>Examples
Example 1
forest = [0, 50, 0, 30, 0, 25]bird = 2return = [3, 1, 5]Pls ignore the explanation in the source image.
Constraints
π¦