Figma·Software Engineer·Technical Phone Screen
- You have multiple rectangles each with a height (minimum height is 1). Given a resize value, if positive distribute it evenly across all rectangles. If negative, reduce heights as evenly as possible while keeping each height at or above 1. For example: resize=-12 with heights [3,5,10,9] should produce [1,1,7,6].
- Extend the previous solution: each rectangle now also has a y-coordinate. After resizing, the relative positions between rectangles must be preserved. Note that relative position is not just the difference in y values but needs to account for rectangle heights.
“The positive case is basically free, just divide and add.”