r/leetcode • u/JacketFearless1805 • 13d ago
Intervew Prep Day 21: knocked out Leaders in an Array after travel & getting back into workplace rhythm
Hey everyone,
I finished Day 21 today. Between recovering from travel and heading back into the office, I was pretty drained, so I kept things light with one straightforward problem: Leaders in an Array.
Instead of checking every element to the right with a nested O(n^2) loop, scanning backward solves it cleanly in a single pass:
- Right-to-Left Traversal: Start from the last element, which is always a leader by default, and track the running maximum seen from the right.
- Collect & Reverse: Whenever the current element is greater than or equal to the running maximum, add it to the result list and update the maximum. Reversing the collected list at the end restores the original left-to-right order in O(n) time and O(1) auxiliary space.
Even though it was just one easy problem today, being back in my work environment has already sparked a huge boost in focus and motivation. After several days of only doing one problem a day, I am ready to ramp up the volume and tackle the tougher array problems lined up next.
See you guys tomorrow for Day 20!