Implementation of deepFlattenAndGroupByTypeWithFrequency
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-06-11
Problem Statement
Design and implement a utility function deepFlattenAndGroupByTypeWithFrequency that takes an arbitrarily nested data structure (e.g., list/array containing mixed data types like numbers, strings, booleans, objects, etc.) and performs the following operations:
1.Deep Flattening
•Traverse the entire nested structure recursively.
•Extract all leaf-level elements into a flat sequence.
2.Grouping by Type
•Group elements by their data type (number, string, boolean, object, etc.).
•Custom type resolution (e.g., arrays → list, dicts → map in Python/Java).
3.Frequency Counting
•For each group, count the frequency of each unique element.
4.Return Structure
•The function should return a nested map/dictionary-like structure: