ENGIE interview question

Flatten a deeply nested array with certain conditions on naming schema