FastPrepArray Nullification
Problems/Array Nullification

Array Nullification

QRT logoQRT● MediumNEW GRADOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given two arrays, change and arr, of lengths n and m, respectively. In each operation i, you can perform one of the following:

  1. You can decrement any element of arr by 1.
  2. 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.

Function

getMinOperations(change: int[], arr: int[]) → int

Complete the function getMinOperations in the editor with the following parameters:

  • int change[n]: an array of integers
  • int arr[m]: an array of integers

Returns:

  • int: the minimum number of operations required to change all the elements to NULL, or -1 if it is not possible

Examples

Example 1

change = [0, 1, 0, 2]arr = [1, 1]return = 4

Operations sequence:

  1. Decrement arr[1]: [0, 1]
  2. Change arr[1] to NULL since change[2] = 1 and arr[1] = 0: [NULL, 1]
  3. Decrement arr[2]: [NULL, 0]
  4. Change arr[2] to NULL since change[4] = 2 and arr[2] = 0: [NULL, NULL]

The answer is 4.

Constraints

  • 1 <= n <= 10^5

More QRT Online Assessment questions

  • 🐘 Keep Them Apart 🦙OA · Seen Jul 2026

Similar questions at other companies

  • Minimum Non-Adjacent Selection CapabilityMicrosoft · OAMicrosoft interview questions
  • Rock JumpingIMC Trading · OAIMC Trading interview questions
  • Minimum Robot and Human Fulfillment TimeAmazon · OA
  • Minimize Maximum Group DifferenceDRW · OADRW interview questions
  • Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
  • Three-Part Partition with Minimum Largest RangeLSEG · OALSEG interview questions
  • K-Means ClusteringAtlassian · OAAtlassian interview questions
  • Get Minimum Development TimeSalesforce · OASalesforce interview questions
  • Job ExecutionMathWorks · OAMathWorks interview questions
  • Police Station 🚓The D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
See QRT hiring insights
Saved
class Solution {
    public int getMinOperations(int[] change, int[] arr) {
      // write your code here
    }
}
Checking account…