#K51227. Flatten Nested Dictionary

    ID: 29041 Type: Default 1000ms 256MiB

Flatten Nested Dictionary

Flatten Nested Dictionary

In this problem, you are given a nested dictionary and an optional custom separator. Your task is to flatten the dictionary such that each key in the output is a concatenation (using the separator) of the keys from the root to the corresponding leaf. More formally, if you have a nested dictionary (d), the output dictionary (f) should satisfy (f[k_1{\text{sep}}k_2{\text{sep}}\cdots{\text{sep}}k_n] = v) for every nested key (k_1, k_2, \ldots, k_n) with corresponding value (v).

For example, given the input dictionary {"a": 1, "b": {"c": 2, "d": {"e": 3}}, "f": {"g": 4}} and the default separator ., the flattened dictionary is {"a": 1, "b.c": 2, "b.d.e": 3, "f.g": 4}.

inputFormat

Input is read from standard input (stdin). The first line contains a valid JSON string representing the nested dictionary. The second line (which may be empty) contains a custom separator. If the second line is empty, use the default separator ..

outputFormat

Output the flattened dictionary as a valid JSON string to standard output (stdout). Ensure that the output format preserves the data types from the input.## sample

{"a": 1}
{"a": 1}