Back to problems

Resize Stacked Rectangles — Distribute Height

Algorithm · Figma · Medium

Requirements Part 1 — Distributing a resize delta across heights You are given a list of rectangle heights (each height is at least 1) and an integer resize that may be positive or negative. When resize > 0: increase every rectangle's height by resize / (number of rectangles). When resize < 0: reduce the rectangles to absorb the delta as evenly as possible, but no rectangle may drop below a height of 1. Any rectangle that would fall under 1 is clamped at 1, and the leftover…

Checking your access…