Minimum Operations to Convert All Elements to Zero
A monotonic stack of distinct positive values counts the operations, because each new value needs one operation unless it is already covered.
A monotonic stack of distinct positive values counts the operations, because each new value needs one operation unless it is already covered.