Array
3619. Count Islands With Total Value Divisible by K
Both examples hand you a count of islands, which tempts you into labelling components first and summing them second. There is no need for two phases: a flood fill that adds a cell's value at the moment it consumes the cell produces the component sum and the component boundary in the same sweep, and the answer is a counter incremented whenever sum % k == 0.
Loading…