FastPrepFind a File in a Directory Snapshot
Problems/Find a File in a Directory Snapshot

Find a File in a Directory Snapshot

Cresta logoCresta● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Cresta online assessment. The report is brief and asks for a file's absolute path. Our version defines the snapshot, matching by exact name, how ties work, and what to return when nothing is found. It is about 70% the same as the reported question.

For this exercise, assume a directory is supplied as a snapshot of its files. rootDir is its absolute path, and every value in relativePaths is the relative path of one regular file below that root, including files in nested directories.

Find files whose last path segment is exactly fileName. Return the matching absolute path that comes first in lexicographic order. If no file matches, return the empty string.

Join the root and relative path with exactly one slash. Matching is case-sensitive and compares the entire filename, including its extension. No real filesystem access is required.

Function

findAbsolutePath(rootDir: String, relativePaths: String[], fileName: String) → String

Examples

Example 1

rootDir = "/work"relativePaths = ["z/log.txt","a/log.txt","notes.md"]fileName = "log.txt"return = "/work/a/log.txt"

Both matching files end in log.txt; /work/a/log.txt is lexicographically smaller.

Example 2

rootDir = "/"relativePaths = ["main.py"]fileName = "main.py"return = "/main.py"

Joining the root with the relative file gives /main.py.

Example 3

rootDir = "/data"relativePaths = ["x/a.txt"]fileName = "b.txt"return = ""

No basename equals b.txt.

Constraints

  • 0 <= relativePaths.length <= 10^4; paths are unique.
  • The root is / or a valid absolute path without a trailing slash. Relative paths have no leading or trailing slash.
  • Segments contain lowercase English letters, digits, dots, underscores or hyphens, and are never . or ...
  • Each path contains at most 200 characters. fileName is one nonempty valid segment.

More Cresta interview questions

  • Decode Words with Anagram KeysOA · Seen Oct 2026
  • Leaves Remaining After WindOA · Seen Oct 2026
  • Maximum Suffix–Prefix OverlapOA · Seen Oct 2026
  • Particle Moves to TargetOA · Seen Jul 2026
  • Rightward Bacteria ConsumptionOA · Seen Jul 2026
  • Top Three Companies by ProfitOA · Seen Jul 2026
  • Peak Chat Load Across AgentsPHONE SCREEN · Seen Nov 2026
  • File Storage ServicePHONE SCREEN · Seen Nov 2026
  • Dynamic Least-Loaded Job DispatcherPHONE SCREEN · Seen Oct 2026
  • Feature Flag Evaluation EngineONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
  • Flat JSON Value DifferencesChubb · OAChubb interview questions
  • Road Trip (Analyst Program :PBlackRock · OABlackRock interview questions
  • Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
  • Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
  • Most Frequent CharacterMicrosoft · OAMicrosoft interview questions
  • Get Maximum Information GainAmazon · OA

Cresta interview experiences

  • Cresta Senior SWE Coding Round Interview Experience: 1 Experience
All Cresta interview questionsSee Cresta hiring insights
Saved
class Solution {
    public String findAbsolutePath(String rootDir, String[] relativePaths, String fileName) {
        // write your code here
    }

}
Checking account…