Repeated Leading-Nonzero Prefix Subtraction

Asked at Capital One · Coding Questions · Difficulty: Easy · Last asked Apr 25, 2026

You are given an array of non-negative integers. Repeatedly take the leftmost nonzero entry, subtract its value from the entries that follow it for as long as they are large enough, add the value to a running total, and clear the entry. Return the total once every entry is zero.

Loading the problem…