File Encryption Plan
Asked at Databricks
Reported by the problem's creator, not verified
You are given a file system tree with n nodes numbered 0 to n - 1. Node 0 is the root directory. parent[i] is the parent of node i, with parent[0] = -1 and parent[i] < i for i > 0. kind[i] is 0 for a directory and 1 for a file; files are leaves. encrypted[i] is true when file i is already encrypted. Directories are never marked encrypted.
Two kinds of calls encrypt files: a call on a file encrypts that one file, and a call on a directory encrypts every file in that directory's subtree at once. Build an EncryptionPlan object that answers queries about the cheapest way to get every file encrypted. Each test creates one instance and checks every method's return value.
Examples
Example 1
Input: init =
[[-1,0,0,1,1],[0,0,1,1,1],[false,false,false,false,true]], operations =[["counts",[]],["min_time",[5,2]],["min_time",[1,5]],["min_time",[100,1]]]Output:
[[1,2],11,12,103]Explanation: Node 4 is the only encrypted file, so
counts()is[1, 2]. Withrequest = 5,per_file = 2, a call on the root costs5 + 3 * 2 = 11because 3 files lie below it, beating two single-file calls at7each. Withrequest = 1,per_file = 5, the two single-file calls cost6each,12in total, while the root call costs16. Withrequest = 100,per_file = 1, one root call costs103, cheaper than202for two file calls.