Pigment interview question

As always, time complexity for the algorithm exercise