Solve array merge and tree flattening problems | Meta Interview Question