I am aware of the recursive way to flatten a nested array. There are several solutions on stackoverflow (both in java and javascript - some using built in libraries).
But the time complexity of these solutions is O(n^2)! I was wondering if there is an algorithm which could do better.
Thanks in advance for your help!