Rakuten interview question

question about algorithm and DS