ThoughtSpot interview question

Write a program to flatten an array based on different levels