Difficulty: 5/10recursion, hash maps, time complexityjavascriptCopyScenario Questions0-2 years experience1We have a utility function that processes user-submitted survey data, which sometimes comes in as nested arrays of scores like `[1, [2, [2, 3]], 1]`. How would you write a function to flatten this data and find the most common score and how many times it appeared?2Imagine you wrote a recursive function to flatten this array, but during testing with a deeply nested array (like 10,000 levels deep), the browser tab crashed with a 'Maximum call stack size exceeded' error. What is happening here, and how would you modify your code to prevent it?Follow-up QuestionsHow would you modify your solution to handle ties where multiple numbers have the same maximum frequency?If the input array is extremely deep (e.g., 20,000 levels), how do you prevent a stack overflow in JavaScript?What is the space complexity of your solution, and can we optimize it if we are memory-constrained?Suggest Improvement