GGK Tech interview question

asked to solve leetcode questions