← Back to challenges

Calculate Depth of Array

PythonHardarraysrecursion

Instructions

Given a list, write a function to calculate it's depth. Assume a normal list has a depth of 1.

Examples

depth([1, 2, 3, 4]) ➞ 1

depth([1, [2, 3, 4]]) ➞ 2

depth([1, [2, [3, 4]]]) ➞ 3

depth([1, [2, [3, [4]]]]) ➞ 4

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.