Write a clean, optimized algorithm to solve a multi-part problem where each subsequent step builds on top of the previous solution's constraints.