Sellavir interview question

Leetcode is the answer for all