A site's navigation menu is nested JSON: each entry is { "label": ..., "children": [...] }, and children may be missing or empty. An entry with no children is a page you can open.
Write breadcrumbs(menu) that returns the breadcrumb for every page: the labels from the top entry down to the page, joined with " / ". List them in the order a depth-first walk reaches the pages, visiting children in their given order.
Input: menu = {"label":"Home","children":[{"label":"Shop","children":[{"label":"Shoes"},{"label":"Bags"}]},{"label":"About"}]} Output: ["Home / Shop / Shoes","Home / Shop / Bags","Home / About"]
Shop has two pages under it, and About is a page itself.
Input: menu = {"label":"Home"} Output: ["Home"]
The top entry has no children, so it is the only page.
1 <= number of entries <= 5000/.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #353 Breadcrumb Trails. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.