FastPrepSquirrel Nut Collection Shortest Path
Problems/Squirrel Nut Collection Shortest Path

Squirrel Nut Collection Shortest Path

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names the squirrel-and-nuts shortest-path exercise but omits coordinates, movement cost, and output shape. This practice uses the conventional Manhattan-grid model with one tree, one squirrel start, and all nuts delivered to the tree. Approximate source match: 65%.

A squirrel, a tree, and some nuts sit on a grid of cells. No two of them share a cell. The squirrel can carry only one nut at a time, and every nut must be brought to the tree.

The squirrel starts at squirrel. It walks to whichever nut it picks first and carries that nut to the tree. After that, every trip starts at the tree, goes to a nut, and comes back to the tree. Return the smallest total Manhattan distance needed to deliver all nuts.

Manhattan distance counts grid steps: take the difference between the two row values and the difference between the two column values, make both positive, and add them.

Function

minSquirrelDistance(tree: int[], squirrel: int[], nuts: int[][]) → int

Examples

Example 1

tree = [2,2]squirrel = [4,4]nuts = [[3,0],[2,5]]return = 12

Each nut is three steps from the tree. The squirrel is also three steps from the nut at [2,5], so it takes that nut first: three steps to the nut and three more to the tree. Then it makes a six-step round trip for the other nut. The total is twelve.

Example 2

tree = [0,0]squirrel = [2,2]nuts = [[1,0]]return = 4

The squirrel walks three steps to the nut and one step from the nut to the tree. The total is four.

Constraints

  • 1 <= nuts.length <= 50000.
  • Every row and column value is in [0, 10000].
  • The tree, the squirrel, and every nut are on different cells.

More Amazon Onsite Interview questions

  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
  • Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Maximize Two Endpoint ValuesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Operations to Make Every Array Element OneOtter.ai · PHONE SCREENOtter.ai interview questions
  • Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
  • Minimize Adjacent Squared-Difference Cost with One InsertionMicrosoft · OAMicrosoft interview questions
  • Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
  • Resource AllocationMaven Securities · OAMaven Securities interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions

Interview reports that mention this question

  • Amazon SDE Onsite Interview Questions: 9 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int minSquirrelDistance(int[] tree, int[] squirrel, int[][] nuts) {
        // Write your code here.
    }
}
Checking account…