FastPrepShortest Path to Food with Directions
Problems/Shortest Path to Food with Directions

Shortest Path to Food with Directions

Zip logoZip● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes a shortest-path graph search with obstacles, names the base problem, and requires a direction string. It leaves out the exact symbols, ties, and its follow-up with a new obstacle. Our version is about 90% the same as the reported question.

You are given a rectangular grid containing exactly one starting cell * and exactly one food cell #. Open cells contain O, and blocked cells contain X.

From an open or starting cell, you may move one step up, down, left, or right without leaving the grid or entering a blocked cell. Return a shortest direction string that moves from * to #. Use the characters U, D, L, and R.

If several shortest strings exist, return the lexicographically smallest one. If the food cannot be reached, return an empty string.

Function

shortestFoodPath(grid: String[]) → String

Examples

Example 1

grid = ["XXXXXX","X*OOOX","XOX#OX","XOOOOX","XXXXXX"]return = "RRD"
grid
0123450XXXXXX1X*OOOX2XOX#OX3XOOOOX4XXXXXX

Move right twice and then down. No route uses fewer than three steps.

Example 2

grid = ["X*O","OO#"]return = "DR"
grid
0120X*O1OO#

Both DR and RD are shortest. DR is lexicographically smaller.

Example 3

grid = ["*X#"]return = ""
grid
0120*X#

The blocked middle cell separates the start from the food.

Constraints

  • 1 <= grid.length <= 200.
  • 1 <= grid[i].length <= 200, and every row has the same length.
  • Every cell is one of *, #, O, or X.
  • The grid contains exactly one * and exactly one #.

More Zip Phone Screen questions

  • Maximum Survival Time in a Graph PursuitPHONE SCREEN · Seen Sep 2026
  • Find All Zip Rummy MeldsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
  • Shortest Path Around Moving ParadesPHONE SCREEN · Seen Mar 2026
  • Furthest Building with Sandbags and RopesPHONE SCREEN · Seen Feb 2026
  • Phrase Covering the Most WordsPHONE SCREEN · Seen Feb 2026
  • Translate Values in a Nested MapPHONE SCREEN · Seen Feb 2026
  • Maximum Nonadjacent Sum in a General TreePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2025
  • Shortest Distance in a GraphPHONE SCREEN · Seen Nov 2025
  • Open the Lock and Return a Shortest PathPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2025
  • Winning Draws for a Mahjong HandPHONE SCREEN · Seen Sep 2025

Similar questions at other companies

  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Shortest Path in a Blocked GridSpotify · PHONE SCREEN
  • Shortest Path in a Binary MatrixMeta · PHONE SCREENMeta interview questions
  • Shortest Grid Path With One Wall BreakAmazon · PHONE SCREEN
  • Place a Service Table Near All CustomersGoogle · PHONE SCREENGoogle interview questions
  • Shortest Path in a Grid with Obstacles EliminationMercor · PHONE SCREENMercor interview questions
  • Shortest Path in a Grid with Obstacles EliminationBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Minimum MovesHarness · OA
  • Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions

Zip interview experiences

  • ZipHQ New Grad OA and Interview Questions: 11 Experiences
  • Zip SWE Interview Timelines: 31 Experiences (Part 2 of 2)
  • Zip SWE OA and Interview Questions: 31 Experiences (Part 1 of 2)
All Zip interview questionsSee Zip hiring insights
Saved
class Solution {
    public String shortestFoodPath(String[] grid) {
        // Write your code here.
    }
}
Checking account…