Rakuten Interview Question

Solve algorithm problem