FastPrepShell Path Autocomplete
Problems/Shell Path Autocomplete

Shell Path Autocomplete

Figma logoFigma● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports describe completing a path by its longest common prefix, for files, for nested paths, and for input that may contain slashes. We chose how absolute paths and no-match cases work. Our version is about 94% the same as the reported questions.

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.

More Figma Phone Screen questions

  • Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Route Graph Reachability with a Broken LinkPHONE SCREEN · Seen Oct 2026
  • Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Layer History with Batch Undo and RedoOA · PHONE SCREEN · Seen Sep 2026
  • Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
  • Intersection of Two RectanglesPHONE SCREEN · Seen Aug 2024
  • Sparse Canvas Paint HistoryPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Search Suggestions with a Prefix TreeCitadel · ONSITE INTERVIEWCitadel interview questions
  • Remove Prefix StringsRoblox · PHONE SCREENRoblox interview questions
  • Every Distinct Substring in OrderAdobe · PHONE SCREENAdobe interview questions
  • Top K Query SuggestionsMicrosoft · PHONE SCREENMicrosoft interview questions
  • Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
  • Suggested ProductsSquarepoint Capital · OASquarepoint Capital interview questions

Figma interview experiences

  • Figma interviews · November 2026
  • Figma SWE Intern OA and Final Round: 21 Experiences
  • Figma SWE Intern OA Questions: 25 Experiences
All Figma interview questionsSee Figma hiring insights
Saved
class Solution {
    public String autocompletePath(String[] paths, String currentDirectory, String input) {
        // Write your code here.
    }
}
Checking account…