Nesting Depth
items is a list whose elements are integers or further lists, nested to any depth. The depth of a list is 1 more than the greatest depth among the lists it directly contains; a list that directly contains no list, including an empty list, has depth 1. Integers have no depth of their own. Return the depth of items.
For example, [1, [2, [3]], 4] has depth 3: the outer list, then [2, [3]], then [3].
Example 1
items [1,[2,[3]],4]
returns 3
[3] has depth 1, so [2, [3]] has depth 2 and the outer list has depth 3.
Example 2
items [1,2,3]
returns 1
The list contains only integers, so its depth is 1.
Constraints
itemsholds at most 100 integers and at most 50 lists in total- Lists are nested at most 10 levels deep
-100 <= value <= 100for every integer
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- One From Each GroupEasy
- Subset SumsEasy
- Subsets by DoublingEasy
- Sum Then ProductEasy
- Teams of a Given SizeEasy
- The Climb FunctionEasy
- Count the BlobsMedium
- Discs After k MovesMedium