Array Nullification
Reported by candidates from QRT's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
QRT's Array Nullification showed up in July 2026 reports, and the detail that trips people is the change array. Each index i is a time slot, and change[i] tells you which element of arr you're allowed to nullify at that exact moment. You have n operations total, and every one is either a decrement or a nullify. The pattern is array plus a binary search on the answer with a greedy check. If you blank when the OA starts, StealthCoder runs invisibly as a safety net while you work, but the idea is simple enough to own before you sit down.
The problem
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: 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. 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: Decrement arr[1]: [0, 1] Change arr[1] to NULL since change[2] = 1 and arr[1] = 0: [NULL, 1] Decrement arr[2]: [NULL, 0] Change arr[2] to NULL since change[4] = 2 and arr[2] = 0: [NULL, NULL] The answer is 4. Constraints 1 <= n <= 10^5
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: if you can finish within T operations, you can finish within T+1. That's monotonic, so binary search on T. For the check, only the last occurrence of each index in change[1..T] matters, because you want to nullify as late as possible and spend the earlier slots decrementing. Walk through the slots in order. At a slot that is the last occurrence of element j, you need arr[j] decrements already banked, so spend that banked time and pay 1 for the nullify. Every other slot adds one decrement credit. If credit is ever short, T fails. Every element must also appear at least once in the prefix. The common pitfall is nullifying at the first occurrence, which wastes decrement time. Another is off-by-one on the 1-based indexing. Return -1 if even T = n fails.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Array Nullification cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as earliest second to mark indices i. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass QRT's OA.
QRT reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Array Nullification FAQ
What's the trick in QRT's Array Nullification?+
Binary search on the number of operations, then greedily check feasibility. For a candidate T, nullify each element at its last appearance in change[1..T]. Every other slot is a free decrement. If banked decrements always cover what's needed at each nullify slot, T works.
How hard is this problem really?+
It's medium-hard. The code is short, but seeing the monotonic answer and the last-occurrence idea takes a moment. Once you see both, it's about 30 lines. The check is O(n + m), so the whole thing runs in O(n log n).
Why use the last occurrence of each index?+
Nullifying later gives you more earlier slots to decrement. Using an early occurrence wastes time that could have reduced arr values. Since the nullify only needs arr[j] to be 0 at that moment, the latest valid slot is always at least as good.
When do I return -1?+
Run the check with T equal to n, the full length of change. If it fails, return -1. That happens when some element never appears in change, or when there aren't enough slots to cover all the decrements plus all the nullify operations.
How do I prepare for this in 48 hours?+
Practice the pattern of binary searching on the answer with a greedy feasibility check. Write the check function by hand on this example: change = [0,1,0,2], arr = [1,1], expecting 4. Then test edge cases like an element missing from change, and arr values of 0.