Frontendx
README.md
SOLUTION.md
main.tsxentry
App.tsx
App.css
index.html
vite.config.ts
Installed
react@^19.2.0
react-dom@^19.2.0

Create Nested Accordion in React — Transform a Flat parentId Array into a Recursively Rendered Collapsible Tree

Prompt

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.

The flat-to-tree conversion should be O(n) using the map for lookups.
Test Results

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.