FastPrepEnumerate Character Paths to a Marker
Problems/Enumerate Character Paths to a Marker

Enumerate Character Paths to a Marker

Tesla logoTesla● MediumFULLTIMEONSITE INTERVIEW

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report asks for depth-first search from the top-left cell, character collection, and a branching follow-up that returns every result. The movement, terminal-marker, ordering, and finite-enumeration rules complete that stable capability.

Given a non-empty rectangular matrix grid whose cells contain either a one-character string or the marker "*", enumerate every simple path from (0, 0) to the marker.

A move goes to an orthogonally adjacent cell, and a path may not visit the same cell twice. Each visited character cell contributes its character to the path string. The marker terminates the path and contributes no character. If grid[0][0] is the marker, the only result is the empty string.

Return all collected strings in lexicographic order. Keep duplicate strings when distinct paths produce the same characters.

Function

enumeratePaths(grid: String[][]) → List<String>

Examples

Example 1

grid = [["a","b"],["c","*"]]return = ["ab","ac"]
grid
010ab1c*

The two simple paths are right then down, producing ab, and down then right, producing ac.

Example 2

grid = [["*"]]return = [""]
grid
00*

The starting cell is terminal, so the one path collects no characters.

Example 3

grid = [["a","a","*"]]return = ["aa"]
grid
0120aa*

The single orthogonal path collects both character cells before reaching the marker.

Constraints

  • 1 <= grid.length and 1 <= grid[i].length.
  • Every row has the same length.
  • The matrix contains at most 20 cells.
  • Exactly one cell contains "*".
  • Every other cell contains a single lowercase English letter.
  • The number of returned paths fits in memory.

More Tesla interview questions

  • Alternate Positive and Negative ValuesONSITE INTERVIEW · Seen Aug 2026
  • Shared Counter Snapshot SumONSITE INTERVIEW · Seen Aug 2026
  • Flatten a Branched List into a Doubly Linked ListPHONE SCREEN · Seen Sep 2026
  • Reduce-Based Map and Filter PipelinePHONE SCREEN · Seen Sep 2026
  • Resilient Fake API ClientPHONE SCREEN · Seen Sep 2026
  • Merge JSON Array FieldsPHONE SCREEN · Seen Aug 2026
  • Count Zero-Sum FragmentsOA · Seen Jun 2026
  • Maximum Insertions Without Three Consecutive AOA · Seen Jun 2026
  • KV Store with RollbackPHONE SCREEN · Seen Apr 2026
  • Maximum Number of Workers with Equal Left and Right ShoesOA · Seen Mar 2025

Similar questions at other companies

  • Trace a Word Through a Letter GridExpedia · ONSITE INTERVIEWExpedia interview questions
  • Word Search with Eight-Direction AdjacencyMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find a Word in a Letter GridAdobe · PHONE SCREENAdobe interview questions
  • Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
  • Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Word SearchAmazon · ONSITE INTERVIEW
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Bounded Combination Sum with Signed CandidatesConfluent · ONSITE INTERVIEWConfluent interview questions

Tesla interview experiences

  • Tesla Experienced Infrastructure SWE Interviews: 1 Experience
  • Tesla Older SWE Intern Reports: 14 Experiences (Part 4 of 4)
  • Tesla Embedded and SRE Intern Loops: 15 Experiences (Part 3 of 4)
  • Tesla SWE and Data Intern Rounds: 10 Experiences (Part 2 of 4)
  • Tesla Intern Python Interview Prep Guide
  • 2017–2026 Tesla Intern OA / Interviews: 83 Experiences (Part 2 :)
All Tesla interview questionsSee Tesla hiring insights
Saved
class Solution {
    public List<String> enumeratePaths(String[][] grid) {
      // write your code here
    }
}
Checking account…