ARRISE interview question

medium question with an optimal approach