Rakuten Interview Question

Basic algorithm question.