Reported May 2022
Figmastring

Shell Path Autocomplete

Reported by candidates from Figma's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Figma OA. Under 2s to a working solution.
Founder's read

Figma's May 2022 OA reportedly asks you to mimic Tab completion in a shell, and the whole thing hinges on a trie built over the file paths. Resolve the input against the current directory, find every path sharing that prefix, then return their longest common prefix. It reads like a string problem, but the input size (200000 paths, 10^6 total characters) is what pushes you toward a trie or a smart sorted scan. If you've got an OA invite and 48 hours, learn this shape now. StealthCoder sits invisibly on your screen as a safety net if the edge cases make you blank mid-assessment.

The problem

Implement path completion similar to pressing Tab in a shell.
You are given absolute file paths, an absolute current directory, and the text already typed by the user. If the typed text is relative, resolve it beneath the current directory. If it begins with /, use it as an absolute prefix.
Find every file path that starts with the resolved prefix. If at least one path matches, return the longest common prefix of all matching absolute paths. Completion may advance through one or more directory components when every match shares them. If no file matches, return the resolved prefix unchanged.

Function
autocompletePath(paths: String[], currentDirectory: String, input: String) → String

Examples
Example 1
paths = ["/home/foo/f1.txt","/home/foo/f1_2.txt","/home/foo/README","/home/foo/bar/f1.txt","/home/foo/bar/README"]
currentDirectory = "/home/foo"
input = "f"
return = "/home/foo/f1"
The two matching files agree through f1, then diverge at. and _.
Example 2
paths = ["/work/folder/file1","/work/folder/file2","/work/folder/file/new","/work/other.txt"]
currentDirectory = "/work"
input = "f"
return = "/work/folder/file"
Every match is inside folder, so completion enters that directory and continues through the shared file prefix.
Example 3
paths = ["/work/folder/file1","/work/folder/file2","/work/folder/image.png"]
currentDirectory = "/tmp"
input = "/work/folder/fi"
return = "/work/folder/file"
An absolute input is completed without using the current directory.

Constraints
1 <= paths.length <= 200000.
The total length of all paths is at most 10^6.
Every path and currentDirectory is absolute and normalized: it contains no repeated slash,., or.. component.
currentDirectory has no trailing slash unless it is /.
input contains no. or.. path component.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two steps. First, resolve the input: if it starts with /, use it as is, otherwise join it to currentDirectory, being careful when the directory is just /. Second, collect every path starting with that prefix and compute their longest common prefix. Simple approach: filter by startsWith, then compare characters across matches. That's linear in total length, which fits the 10^6 limit, so a trie isn't strictly required. Or sort the matches and compare only the first and last. The common pitfalls: double slashes when joining, returning the resolved prefix when nothing matches, and forgetting that the common prefix can run past the typed text across directory boundaries, as in Example 2. Also remember the common prefix is character-level, not component-level. If you freeze on the join logic or the no-match case during the live OA, StealthCoder is the hedge that hands you a clean solution.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Shell Path Autocomplete cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Figma's OA.

Figma reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Shell Path Autocomplete FAQ

What's the actual trick in the Figma path autocomplete problem?+

Resolve the input into an absolute prefix, filter paths that start with it, then take the longest common prefix of the matches. Character-level comparison handles directory crossings automatically. If nothing matches, return the resolved prefix unchanged.

Do I need a trie for this?+

Not strictly. A linear filter with startsWith plus a common-prefix pass runs in time proportional to total path length, which fits the 10^6 limit. A trie works too and is the cleaner answer if you expect repeated queries, but one query doesn't need it.

What edge cases break most solutions?+

Joining currentDirectory when it's just /, which creates a double slash. Returning an empty string instead of the resolved prefix when nothing matches. Treating the prefix as component-based when it's character-based, so f should complete to f1 in Example 1.

How hard is this one really?+

Easy to medium. The algorithm is short, but the spec has several small rules and it's easy to miss one. Most lost points come from path joining and the no-match fallback, not from the prefix logic itself.

How do I prepare in 48 hours?+

Write the prefix resolver and a longest-common-prefix helper from scratch, then test on the three examples plus a no-match case and a root directory case. Practice the sorted first-and-last trick for common prefix. That covers nearly everything this problem tests.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Figma.

OA at Figma?
Invisible during screen share
Get it