Array Nullification

Company: Mathworks_8aug

Difficulty: medium

Problem Statement

Array Nullification Problem Description You are given an array arr of m positive integers and a list change of n integers. Both are 1-indexed . The goal is to change every element of arr to NULL . The operations happen in a fixed order: operation 1 , then operation 2 , and so on up to operation n . In operation i you may do at most one of the following: Decrement any one element of arr that is not NULL by 1 . Nullify: if change[i] = j with j != 0 , and arr[j] is currently exactly 0 , change arr[j] to NULL . Do nothing. (inferred -- the source does not say whether an operation may be left unused; its sample explanation simply skips operations it does not need, so an unused operation is allowed.) Find the minimum k such that, using only operations 1 to k , every element of arr can be made NULL . The answer counts every operation from 1 to k , including any that were left unused. If it is impossible even with all n operations, return -1 . Function Description Complete the function getMinO