FastPrepFastPrep
Problem Brief

πŸ¦‰ Collect Sticks

FULLTIMEOA

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.
  • 1Example 1

    Input
    forest = [0, 50, 0, 30, 0, 25], bird = 2
    Output
    [3, 1, 5]
    Explanation
    Pls ignore the explanation in the source image.

    Constraints

    Limits and guarantees your solution can rely on.

    πŸ¦‰
    public List<Integer> collectSticks(int[] forest, int bird) {
      // write your code here
    }
    
    Input

    forest

    [0, 50, 0, 30, 0, 25]

    bird

    2

    Output

    [3, 1, 5]

    Sign in to submit your solution.