PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Dropbox

Implement hierarchical folder access check

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of hierarchical data structures, access-control semantics, ancestor/descendant relationships, and efficient query handling for repeated membership checks.

  • medium
  • Dropbox
  • Coding & Algorithms
  • Software Engineer

Implement hierarchical folder access check

Company: Dropbox

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are asked to simulate a simple hierarchical file system and implement an access-check function. The file system consists of folders arranged in a tree. A user is granted **direct access** to a subset of folders. Access is **inherited down the tree**: if the user has access to a parent folder, they automatically have access to all of its descendant folders. You are given: - A list of all folders in the system, represented as absolute paths from the root. For example, a tree like: ```text / ├── A │ ├── B │ │ ├── C │ │ └── D │ └── E └── F ``` could be represented as: ```text allFolders = [ "/", "/A", "/A/B", "/A/B/C", "/A/B/D", "/A/E", "/F" ] ``` - A set of folder paths `accessibleFolders` representing folders to which the user has **direct** access. For example: ```text accessibleFolders = { "/A", "/F" } ``` You need to implement the function: ```text bool HasAccess(string folderPath) ``` that returns: - `true` if the user has access to `folderPath` **either** because: - `folderPath` is in `accessibleFolders`, **or** - some ancestor folder of `folderPath` (e.g., `/A` is an ancestor of `/A/B/C`) is in `accessibleFolders`. - `false` otherwise. Assume: - All folder paths in `allFolders` and `accessibleFolders` are normalized absolute paths starting with `'/'`, with components separated by `'/'` (e.g., `/A/B/C`). - `folderPath` passed into `HasAccess` is always a valid folder path present in `allFolders`. Examples (given the tree above and `accessibleFolders = {"/A", "/F"}`): - `HasAccess("/A")` → `true` (direct access) - `HasAccess("/A/B")` → `true` (inherits from `/A`) - `HasAccess("/A/B/C")` → `true` (inherits from `/A`) - `HasAccess("/A/E")` → `true` (inherits from `/A`) - `HasAccess("/F")` → `true` (direct access) - `HasAccess("/")` → `false` (no access to root unless `/` is in `accessibleFolders`) Design and implement `HasAccess` so that it can be called many times efficiently after the initial inputs (`allFolders` and `accessibleFolders`) are known.

Quick Answer: This question evaluates understanding of hierarchical data structures, access-control semantics, ancestor/descendant relationships, and efficient query handling for repeated membership checks.

Related Interview Questions

  • Compute worst-case guesses for adaptive hangman - Dropbox (medium)
  • Return all files under a path - Dropbox (medium)
  • Build a hit/miss word guessing game - Dropbox (medium)
  • Implement feedback for word guessing game - Dropbox (medium)
  • Review checkout code for defects and privacy - Dropbox (Medium)
Dropbox logo
Dropbox
Oct 18, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0

You are asked to simulate a simple hierarchical file system and implement an access-check function.

The file system consists of folders arranged in a tree. A user is granted direct access to a subset of folders. Access is inherited down the tree: if the user has access to a parent folder, they automatically have access to all of its descendant folders.

You are given:

  • A list of all folders in the system, represented as absolute paths from the root. For example, a tree like:
/
├── A
│   ├── B
│   │   ├── C
│   │   └── D
│   └── E
└── F

could be represented as:

allFolders = [
  "/",      
  "/A",
  "/A/B",
  "/A/B/C",
  "/A/B/D",
  "/A/E",
  "/F"
]
  • A set of folder paths accessibleFolders representing folders to which the user has direct access. For example:
accessibleFolders = { "/A", "/F" }

You need to implement the function:

bool HasAccess(string folderPath)

that returns:

  • true if the user has access to folderPath either because:
    • folderPath is in accessibleFolders , or
    • some ancestor folder of folderPath (e.g., /A is an ancestor of /A/B/C ) is in accessibleFolders .
  • false otherwise.

Assume:

  • All folder paths in allFolders and accessibleFolders are normalized absolute paths starting with '/' , with components separated by '/' (e.g., /A/B/C ).
  • folderPath passed into HasAccess is always a valid folder path present in allFolders .

Examples (given the tree above and accessibleFolders = {"/A", "/F"}):

  • HasAccess("/A") → true (direct access)
  • HasAccess("/A/B") → true (inherits from /A )
  • HasAccess("/A/B/C") → true (inherits from /A )
  • HasAccess("/A/E") → true (inherits from /A )
  • HasAccess("/F") → true (direct access)
  • HasAccess("/") → false (no access to root unless / is in accessibleFolders )

Design and implement HasAccess so that it can be called many times efficiently after the initial inputs (allFolders and accessibleFolders) are known.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Dropbox•More Software Engineer•Dropbox Software Engineer•Dropbox Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.