In a design tool, a layer list is an array whose items are layer ids (numbers) or groups. A group is another array with the same rules, so groups can hold groups.
Write nestingDepth(layers) that returns how deep the nesting goes. A list with no groups inside it has depth 1. A list that contains groups has depth 1 plus the largest depth among its groups. An empty list has depth 1.
Input: layers = [1,[2,[3]],4] Output: 3
The outer list holds [2, [3]], which holds [3]: three levels.
Input: layers = [1,2,3] Output: 1
No groups, so the depth is 1.
1000 items in total.100 levels deep.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 #5 Deepest Layer Group. 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.