Mission Lane interview question

Standard leetcode DS question for the first technical round