FastPrepCollect Letters Along a Unique Grid Path
Problems/Collect Letters Along a Unique Grid Path

Collect Letters Along a Unique Grid Path

Apple logoApple● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple full-time online assessment. The task of following a path through a grid is about 90% the same as the report. We chose these rules: dot cells, a path that is fully connected, and what to return when there are no letters or only one cell.

You are given a grid with 10 rows and 15 columns. It holds exactly one path. Each cell on the path is either * or a lowercase English letter. Every other cell is unused.

The path starts at (0, 0), which is one end of the path. Each step moves up, down, left, or right to the next cell. The path never splits into branches and never loops back on itself.

Walk the path from its start to its other end. Each time you reach a letter, add it to the end of your answer. Skip the stars. Return the string you built.

Unused cells hold ., so every cell that is not a dot is on the path. The path may be a single cell, and it may contain no letters at all.

Function

collectPathLetters(grid: String[]) → String

Examples

Example 1

grid = ["*a*............","..b............","c**............","...............","...............","...............","...............","...............","...............","..............."]return = "abc"

Starting at the top-left star, the path goes right through a, then down through b, then left along the bottom of the path to c. Skipping the stars, the letters in order are a, b, and c, so the answer is abc.

Example 2

grid = ["x..............","*..............","y..............","...............","...............","...............","...............","...............","...............","..............."]return = "xy"

The path starts on x, goes down through a star, and ends on y. Both ends are letters, so the answer is xy.

Constraints

  • grid.length == 10.
  • Every row has exactly 15 characters.
  • Each character is ., *, or a lowercase English letter.
  • The cells that are not dots form one single path, with no branches and no loops. Each step on it goes up, down, left, or right. One end of this path is (0, 0).

More Apple interview questions

  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge Two Strings by Maximum Boundary OverlapOA · Seen Sep 2026
  • Maximum Weight in Two BagsOA · Seen Aug 2025
  • Ignore SectionsOA · Seen Mar 2024
  • Gas Station Circular TourOA · Seen Nov 2021
  • House Robber IIOA · Seen Nov 2021
  • Clone an Undirected Graph StateOA · Seen Mar 2021
  • Longest Increasing Subsequence LengthOA · Seen Feb 2021
  • Maximum Later DifferenceOA · Seen Feb 2021
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions
  • Repair One Movement InstructionOpenAI · OAOpenAI interview questions
  • Count Straight-Line Word Occurrences in a GridOptiver · OAOptiver interview questions
  • Count Straight-Line Word Occurrences in a GridVisa · OAVisa interview questions
  • Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
  • Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
  • Excel Training Data and Model Response AuditMicrosoft · PHONE SCREENMicrosoft interview questions
  • BitFont Part 1 - Render a CharacterStripe · ONSITE INTERVIEWStripe interview questions
  • Alphabet Board PathZillow · ONSITE INTERVIEWZillow interview questions
  • Cyclic Fuel Command SimulationWaymo · ONSITE INTERVIEWWaymo interview questions

Interview reports that mention this question

  • Apple India SWE New Grad Interviews: 5 Experiences

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public String collectPathLetters(String[] grid) {
        // Write your solution here.
    }

}
Checking account…