FastPrepRemove Redundant Directory Grants
Problems/Remove Redundant Directory Grants

Remove Redundant Directory Grants

Dropbox logoDropbox● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports describe inherited directory access, and a follow-up about removing grants on subfolders that a parent folder already covers. This version defines the input as a forest and gives the output a fixed order. Our version is about 93% the same as the reported question.

A user has explicit access grants to some directories in a directory forest. A grant to a directory also grants access to every descendant of that directory.

The parallel arrays directories and parents describe the forest. For each index i, parents[i] is the direct parent of directories[i], or the empty string when that directory is a root.

Given the distinct explicitly granted directories in grants, remove every grant whose directory has a granted ancestor. Return the remaining grants in their original order in grants.

A grant is never redundant merely because it has a granted descendant. Only an explicit grant on a strict ancestor makes it redundant.

Function

removeRedundantGrants(directories: String[], parents: String[], grants: String[]) → String[]

Examples

Example 1

directories = ["A","B","C"]parents = ["","A","A"]grants = ["A","B","C"]return = ["A"]

The grant on A already grants access to both children, so the explicit grants on B and C are redundant.

Example 2

directories = ["A","B","C","D","E","F","G","H","I"]parents = ["","A","A","C","C","E","F","B","B"]grants = ["E","I","G"]return = ["E","I"]

G is a descendant of the granted directory E, so its grant is removed. Neither E nor I has a granted ancestor.

Constraints

  • 1 <= directories.length <= 2 * 10^5
  • parents.length == directories.length
  • Every directory name is a unique non-empty string.
  • Each parents[i] is either the empty string or names a different directory in directories.
  • The parent relationships form a forest with no cycles.
  • 0 <= grants.length <= directories.length
  • Every value in grants names a directory and appears at most once.
  • The total number of characters across all input strings is at most 2 * 10^6.

More Dropbox interview questions

  • Find Duplicate Files by ContentONSITE INTERVIEW · Seen Feb 2021
  • Reusable Number AllocatorONSITE INTERVIEW · Seen Feb 2021

Similar questions at other companies

  • N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
  • Merge N-Ary Trees by KeyLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Render a Stable Comment HierarchyBobyard · PHONE SCREEN
  • Translate Values in a Nested MapZip · PHONE SCREENZip interview questions
  • Build a Trace ForestDatadog · PHONE SCREENDatadog interview questions
  • Transform and Prune a Mode-Valued Binary TreeGoogle · PHONE SCREENGoogle interview questions
  • Topmost Accessible NodesFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
All Dropbox interview questionsSee Dropbox hiring insights
Saved
class Solution {
    public String[] removeRedundantGrants(String[] directories, String[] parents, String[] grants) {
        // Write your code here.
    }
}
Checking account…