Build a Nested Comment Tree from Parent IDs

You are given a flat list of comments. Each comment contains a unique id, a parentId, and a text field. Root comments have parentId = null.

Convert the flat comments into a nested comment for...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: