elminda interview question

I had to solve a coding task