Collect Letters Along a Unique Grid Path
Updated
Problem statement
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[]) → StringExamples
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
15characters. - 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