The interview had a mix of DSA, project discussion, and behavioral questions based on Amazon Leadership Principles.
DSA: I was given a grid-based problem involving a forest where different cells contained trees of different heights. The objective was to start from the top-left cell and remove all the trees in increasing order of their heights, while moving only up, down, left, or right through walkable cells.
A cell containing 0 was blocked, while positive values represented walkable cells. After cutting a tree, that cell became an empty walkable cell. The task was to find the minimum number of moves required to remove every tree, or return -1 if some tree could not be reached.
The interviewer first asked me to explain the approach and then write the code.
I initially considered whether a single BFS could be used to traverse the entire grid and handle all the trees together. During the discussion, I realized that this would not correctly capture the requirement of visiting the trees in their specified height order.
Approach: Sort the trees by height and run BFS between consecutive trees to find the shortest path. Add each BFS distance to the answer; if any tree is unreachable, return -1.
There was also a project discussion followed by Leadership Principle–based behavioral questions, with most questions revolving around my project and my actual experiences.
Some questions were: