ThoughtSpot Interview Question

Write a program to flatten an array based on different levels