Kickstart 2019 : Round F- Problem Flattening

Problem: https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050edc/000000000018666c

Can anyone please explain me the approach to the above mentioned problem. ?

Link to the solution with comments for understanding

https://ide.geeksforgeeks.org/kmxuyWSEJT