Bending Spoons Interview Question

An algorithm design programming question, including a final step with optimisation + explanation of my solution.