FunctionRacerProblemsRace

Nesting Depth

EasyRecursionPython, JavaScript, TypeScript

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems