Encrypted File Count and Minimum Time
Updated
Problem statement
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-1for the root.type[i]is0for a directory or1for a file.encrypted[i]gives a file's initial encryption state. It isfalsefor 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 + fileTimeand encrypts that file. - A directory call costs
requestTime + N * fileTimeand encrypts every currently unencrypted file in that directory's subtree. For this exercise,Nis 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 <= 200000parent[0] = -1; fori > 0,0 <= parent[i] < i.- The root is a directory, and every file node has no children.
encrypted[i]isfalsefor 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