Rakuten interview question

Basic algorithm question.