Klarna interview question

Typical medium two algorithm problems