FastPrepFastPrep
Problem Brief

Retention Policy Collision

OA

Box Governance customers can create Retention Policies that will hold files for a certain length of time. When placed on a folder, all files in that folder can not be deleted until the length of time has passed. Once a Retention Policy has been created and put on a folder, the customers can move the policy up and down their folder tree onto different folders.

There are n Retention Policies placed on the Box folder tree that constantly love up or down the folder tree onto different folders. The folder tree is infinitely long, so policies will move up or down infinitely. direction[i] represents the direction in which the i-th Retention Policy is moving with -1 meaning that it is moving up the folder tree and 1 meaning it is down the folder tree. The policy length (how long the policy will hold files for) of the i-th Retention Policy is described by length[i]. If 2 Retention Policy collide, the one with the higher length destroys the smaller one. If both have the same length, both are destroyed. Return a list of the indices of the policies that remain after all the collisions have occured, in an ascending order.

Note that the array direction and length are 0-indexed.

Function Description

Complete the function findRemainingPolicies in the editor.

1Example 1

Input
direction = [1, -1], length = [2, 1]
Output
[0]
Explanation
The example shows how 2 retention policies are listed in order of occurrence from left to right, so policy 0 is somewhere higher in the folder tree than policy 1. Retention Policy 0 is moving down the folder tree and Retention Policy 1 is moving up the folder tree. The policies will collide at some point and the policy with the higher length, policy 0, survives. Return [0] as the answer;
public int[] findRemainingPolicies(int[] direction, int[] length) {
  // write your code here
}
Input

direction

[1, -1]

length

[2, 1]

Output

[0]

Sign in to submit your solution.