Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created May 22, 2025 22:02
Show Gist options
  • Save Ifihan/4e5a2455fea79c2dd1003c655d7d2142 to your computer and use it in GitHub Desktop.
Save Ifihan/4e5a2455fea79c2dd1003c655d7d2142 to your computer and use it in GitHub Desktop.
Zero Array Transformation III

Question

Approach

I approached the problem by realizing I need to ensure each index i in nums is decremented at least nums[i] times. I used a difference array to simulate how many times each index is affected by the remaining queries. Then, I binary searched on the number of queries I could safely remove while still converting nums into a zero array. 486 / 824 testcases passed.

Then the editorial

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment