#C11136. Maximum Nested Array Depth
Maximum Nested Array Depth
Maximum Nested Array Depth
You are given a possibly nested array (list) in JSON format. Your task is to determine its maximum nesting depth.
The depth of a non-nested element is defined as 1. For an array that contains nested arrays, the depth is computed using the formula:
$$\text{depth} = 1 + \max(\text{depths of nested arrays})$$
For example, the array [1, [2, 3]]
has a depth of 2, and [1, [2, [3, 4]]]
has a depth of 3.
Note that even if some inner arrays are empty (e.g. []
), they still count as an array and increase the depth accordingly.
inputFormat
The input consists of a single line containing a JSON array representation. The array may contain integers or other arrays nested arbitrarily.
Examples of valid inputs:
- [1, 2, 3]
- [1, [2, 3]]
- [1, [2, [3, 4]]]
outputFormat
Output the maximum depth (an integer) of the provided nested array on a single line.
## sample[1,2,3]
1