#C285. Maximum Depth of Nested Dictionary
Maximum Depth of Nested Dictionary
Maximum Depth of Nested Dictionary
You are given a JSON value representing a nested dictionary. Your task is to compute the maximum depth of the nested dictionary. The depth of a dictionary is defined as follows:
If the input is not a dictionary or is an empty dictionary, its depth is 1. Otherwise, the depth is 1 + the maximum depth among all dictionary values.
For example:
{"a": 1, "b": 2}
has a depth of 1.{"a": 1, "b": {"c": 2, "d": {"e": 3}}}
has a depth of 3.
You need to read the input from standard input (stdin) and write the result to standard output (stdout) as an integer representing the maximum depth.
inputFormat
The input consists of a single line containing a valid JSON value. This value can either be a dictionary (object) with nested dictionaries or any other JSON type. Note that if the provided input is not a dictionary, the depth is defined as 1.
Examples of valid inputs:
{"a": 1, "b": 2}
{"a": 1, "b": {"c": 2, "d": {"e": 3}}}
{}
42
outputFormat
Output a single integer which is the maximum depth of the input dictionary.
## sample{"a":1,"b":2}
1