X interview question

Leetcode : Nested list