Deep Merge of Two Objects — LeetCode 2755 Python Solution
MediumLeetCode PremiumJavaScript
- Problem
- #2755
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given two values obj1 and obj2, return a deepmerged value. Values should be deepmerged according to these rules: If the two values are objects, the resulting object should have all the keys that exist on either object.
Example
- Input
- obj1 = {"a": 1, "c": 3}, obj2 = {"a": 2, "b": 2}
- Output
- {"a": 2, "c": 3, "b": 2}
- Explanation
- The value of obj1["a"] changed to 2 because if both objects have the same key and their value is not an array or object then we change the obj1 value to the obj2 value. Key "b" with value was added to obj1 as it doesn't exist in obj1.
Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2755. Deep Merge of Two Objects?
- LeetCode 2755. Deep Merge of Two Objects is rated Medium on LeetCode.
- What topics does LeetCode 2755. Deep Merge of Two Objects cover?
- LeetCode 2755. Deep Merge of Two Objects is tagged JavaScript on LeetCode.
- Is LeetCode 2755. Deep Merge of Two Objects a premium problem?
- Yes. LeetCode 2755. Deep Merge of Two Objects is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.