Rakuten Interview Question

From Data Structures and Algorithm.