FastPrepEncrypted File Count and Minimum Time
Problems/Encrypted File Count and Minimum Time

Encrypted File Count and Minimum Time

Databricks logoDatabricks● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Databricks phone screen. The original report gives the file-system tree, the counting task, both encryption operations, and the goal of the least time. It leaves unclear what N is for the directory operation. Our version uses a fixed way of processing in bulk, described below. It is about 92% the same as the reported question.

A rooted file-system tree contains directory nodes and file nodes. Node 0 is the root. For each node i:

  • parent[i] is its parent, or -1 for the root.
  • type[i] is 0 for a directory or 1 for a file.
  • encrypted[i] gives a file's initial encryption state. It is false for directories.

First, count the initially encrypted and initially unencrypted files.

Then make every file encrypted using these operations:

  • A file call on an unencrypted file costs requestTime + fileTime and encrypts that file.
  • A directory call costs requestTime + N * fileTime and encrypts every currently unencrypted file in that directory's subtree. For this exercise, N is the total number of file nodes in the subtree, including files that were already encrypted.

Each initially unencrypted file must be encrypted exactly once. Return a three-element array [encryptedCount, unencryptedCount, minimumTime], where the counts describe the initial tree and minimumTime is the least total operation cost.

Function

fileEncryptionSummary(parent: int[], type: int[], encrypted: boolean[], requestTime: long, fileTime: long) → long[]

Examples

Example 1

parent = [-1,0,0,1,1]type = [0,0,1,1,1]encrypted = [false,false,false,false,true]requestTime = 5fileTime = 2return = [1,2,11]

Initially, one file is encrypted and two are not. Processing directory 1 in bulk costs 9, while encrypting only its unencrypted file costs 7. At the root, one bulk call costs 5 + 3 * 2 = 11, which is less than combining the best child plans for a total of 14.

Example 2

parent = [-1,0,0]type = [0,1,1]encrypted = [false,true,true]requestTime = 4fileTime = 3return = [2,0,0]

Both files are already encrypted, so no operation is needed.

Constraints

  • 1 <= parent.length = type.length = encrypted.length <= 200000
  • parent[0] = -1; for i > 0, 0 <= parent[i] < i.
  • The root is a directory, and every file node has no children.
  • encrypted[i] is false for every directory.
  • 0 <= requestTime, fileTime <= 10^9.
  • The minimum time fits in a signed 64-bit integer.

More Databricks Phone Screen questions

  • Rolling Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimize CommuteOA · PHONE SCREEN · Seen Oct 2026
  • Top-K Values per Key in MapReducePHONE SCREEN · Seen Oct 2026
  • Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Circuit Breaker Database FailoverPHONE SCREEN · Seen Aug 2026
  • Find First Anagram IndexPHONE SCREEN · Seen Aug 2026
  • Ordered IP FirewallPHONE SCREEN · Seen Aug 2026
  • Key-Value Store GET and PUT QPSPHONE SCREEN · Seen Aug 2026
  • Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Lowest Common Manager for Employee GroupsAmazon · PHONE SCREEN
  • Lowest Common Manager for Employee GroupsGoogle · PHONE SCREENGoogle interview questions
  • Maximum Path Sum Between Marked NodesDoorDash · PHONE SCREENDoorDash interview questions
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • House Robber IIIVisa · PHONE SCREENVisa interview questions
  • Maximum Nonadjacent Sum in a General TreeZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
  • Minimum-Cost Root-to-Leaf Path in an N-ary TreeBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
  • Part 2: Batch Access ReviewScale AI · OAScale AI interview questions

Databricks interview experiences

  • Databricks Senior SWE Onsite AI Rounds: 1 Experience
All Databricks interview questionsSee Databricks hiring insights
Saved
class Solution {
    public long[] fileEncryptionSummary(int[] parent, int[] type, boolean[] encrypted, long requestTime, long fileTime) {
        // Write your solution here.
    }
}
Checking account…