Domanda di colloquio di Stack Lighting

Simple Greedy algorithm question solved using brute forced then optimize it using some data structure. I was able to use any language I wanted, I ended up writing it in pseudocode.