Category tree

A code exercise of about 15 minutes: read the statement, solve «Category tree» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

Write buildTree(categories). You get flat categories { id, parentId, name } (parentId is null for roots), like an online shop's. Return the roots with their children nested in children, sorted by name at every level. Categories whose parent doesn't exist are ignored.