#C1197. Deep Merge of Nested Dictionaries
Deep Merge of Nested Dictionaries
Deep Merge of Nested Dictionaries
Given two nested dictionaries represented in JSON format, your task is to merge them recursively using the following rules:
- If the values corresponding to the same key in both dictionaries are JSON objects, merge them recursively.
- If both values are arrays, concatenate them.
- Otherwise, the value from the second dictionary overwrites the value from the first dictionary.
This problem tests your ability to process nested data structures and perform recursive algorithms. The input is provided via standard input (stdin) and the output must be printed to standard output (stdout) in JSON format.
inputFormat
Input is read from standard input (stdin). The first line is a JSON string representing the first dictionary, and the second line is a JSON string representing the second dictionary.
outputFormat
Output the merged dictionary in JSON format on a single line to standard output (stdout).## sample
{"a": 1, "b": {"x": 5}}
{"b": {"y": [3, 4]}, "c": 2}
{"a":1,"b":{"x":5,"y":[3,4]},"c":2}