Company: Mathworks_17july
Difficulty: medium
Array Nullification Problem Description You are given two arrays, change and arr , of lengths n and m , respectively. In each operation, you can perform one of the following: You can decrement any element of arr by 1. If change[i] == 0 and arr[change[i]] >= 0 , you can change that element to NULL. Assume 1-based indexing and find the minimum number of operations required to change all elements of the array to NULL, or report -1 if not possible. Examples Example 1: n = 4, m = 2 change = [0, 1, 0, 2] arr = [1, 1] Operations sequence: Decrement arr[1] : [0, 1] Change arr[1] to NULL since change[1]=1 and arr[1]=0 : [NULL, 1] Decrement arr[2] : [NULL, 0] Change arr[2] to NULL since change[2]=0 and arr[2]=0 : [NULL, NULL] The answer is 4. Example 2: (Sample Case 0) Input: change[] size n = 10 change = [1, 0, 1, 3, 2, 1, 0, 3, 1, 1] arr[] size m = 3 arr = [2, 1, 2] Output: 8 Explanation: One of the possible operation flows can be: Decrement arr[1] : [1,