Upwork interview question

Basic algorithms.