Get Minimum Operations

Asked at Rubrik · Coding Questions · Difficulty: Hard

Given two arrays `change` (length `n`) and `arr` (length `m`). Operations happen in order `i = 1..n`. In the `i`-th operation you may decrement any single element of `arr` by 1 (or do nothing); additionally, if `change[i] > 0` and `arr[change[i]] == 0` (1-indexed), that element becomes NULL. Find the minimum number of operations to make every element of `arr` NULL, or `-1` if impossible.

Loading the problem…