Heyzap interview question

Typical big O and easy algorithm