Company: Uber
Difficulty: medium
Bird\'s Nest Building You are helping the bird build its nest. You are given an array forest , containing positive integers and zeros, and a non-negative integer bird , representing the bird\'s initial position. Each positive integer within the forest is considered to be a stick, where forest[i] represents the length of the i th stick. Each zero within forest[i] represents that this place is empty. Initially, the bird is located at forest[bird] , which is guaranteed to be zero. The bird builds its nest, following the algorithm: The bird flies to the right until it finds a stick; The bird flies back to its initial position and attaches the found stick to the nest; The bird repeats steps one and two, but changes the flight direction - it now flies to the left; The bird will repeat steps one and two, changing to the opposite direction each time, until the total length of the sticks in the nest reaches 100. Constraints It is guaranteed that the total length of all sticks in the forest is g