Create Nested Accordion in React — Transform a Flat parentId Array into a Recursively Rendered Collapsible Tree
Given a flat array of objects with id, name, and parentId fields, transform it into a nested tree structure and render it as a nested accordion in React. Nodes with parentId: null are root-level items; all other nodes are children of the node whose id matches their parentId. Convert the flat array into a tree using a Map-based O(n) algorithm. Recursively render each node as an accordion item — clicking the header toggles its children in/out. This evaluates your data transformation skill as much as your component design. It is also a sub-question of MakeMyTrip's machine coding question. This was asked in Apple's IC3 frontend interview.