Collect Sticks for a Bird's Nest
Reported by candidates from Duolingo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Duolingo reported this one in October 2025, and it looks cute until you read it twice. A bird sits at an index, grabs sticks alternating right then left, and stops once the total hits 100. Under the story it's a simulation with two pointers walking outward from the bird. No fancy data structure, no trick algorithm. If you've got an OA invite, the risk isn't difficulty, it's sloppy pointer handling under a clock. StealthCoder is the safety net if you blank live, but this one is mostly about reading carefully.
The problem
You are helping a bird build its nest. You are given an integer array forest containing positive integers and zeros, and an index bird representing the bird's initial position. Each positive value forest[i] is a stick whose length equals that value. Each zero is an empty position. The starting position is guaranteed to be empty. The bird follows this process: Fly to the right until reaching the first remaining stick, take that stick, and return to bird. Fly to the left until reaching the first remaining stick, take that stick, and return to bird. Continue alternating right and left until the total length of collected sticks is at least 100. Return the original zero-based indices of the collected sticks in the order in which the bird finds them. Function collectNestSticks(forest: int[], bird: int) → int[] Examples Example 1 forest = [25,0,50,0,0,0,0,15,0,0,45] bird = 4 return = [7,2,10] The first stick to the right is at index 7 with length 15. The first stick to the left is at index 2 with length 50. Moving right again finds index 10 with length 45. The collected total is 110, so the process stops. Constraints forest[bird] = 0. Every value in forest is a non-negative integer; every positive value is a stick length. The sum of all stick lengths is at least 100. Before the collected total reaches 100, the next required direction always contains a remaining stick. A solution with time complexity no worse than O(forest.length^2) fits the source's execution limit.
Reported by candidates. Source: FastPrep
Pattern and pitfall
What it really reduces to: keep a right pointer starting at bird+1 and a left pointer starting at bird-1. On a right turn, advance the right pointer until forest[r] is positive, record r, add its length, then move on. On a left turn, do the same going down. Alternate with a boolean flag and stop the moment the running sum is at least 100. Check the sum right after each pick, not at the end of a round. In Example 1 the stop happens after a right pick, so a round-based check would break. Pointers only move one way, so it's O(n). The constraints guarantee a stick exists in the needed direction, so you don't need bounds fallbacks, but guard indexes anyway. If you freeze live, StealthCoder is the hedge, but the logic is short enough to write cold.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Collect Sticks for a Bird's Nest cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Duolingo's OA.
Duolingo reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Collect Sticks for a Bird's Nest FAQ
How hard is the Duolingo bird nest problem really?+
Easy. It's a straight simulation with two pointers and a running sum. The only real difficulty is the story wrapper and getting the stop condition right. If you can write a while loop with an alternating flag, you can solve it in a few minutes.
What's the trick to Collect Sticks for a Bird's Nest?+
Don't rescan from the bird each time. Keep a right pointer and a left pointer that only move outward, skipping zeros. Alternate directions, record the original index of each stick you take, and stop as soon as the total reaches 100.
Where do people usually get this wrong?+
Checking the 100 threshold at the wrong time. You must check after every single pick, since the process can end mid-round after a right pick. Another slip is returning values instead of original indices, or restarting the scan from bird each turn.
What's the time complexity I should aim for?+
O(n) is easy with two outward-moving pointers, since each cell is visited at most once. The problem says O(n^2) is acceptable, so even a naive rescan passes, but the pointer approach is cleaner and avoids bugs with already-taken sticks.
How do I prepare for this in 48 hours?+
Practice simulation problems with two pointers and alternating turns. Write this one from scratch once, then test edge cases: bird near an edge, sticks adjacent, and a stop right after a right pick. Trace Example 1 by hand until [7,2,10] comes out.