The Deep Merge of Two Objects interview question asks you to implement a function that merges two objects or JSON structures. Unlike a "shallow merge" (which only copies top-level properties), a "deep merge" recursively combines nested objects and arrays. If both objects have the same key, the value from the second object usually overrides the first, unless both are objects/arrays, in which case they should be merged. This Deep Merge of Two Objects coding problem is a test of recursive data structures.
Valve and other companies use this to test a candidate's mastery of Recursion and their understanding of object types. It evaluates if you can handle edge cases like mixing arrays and objects, handling null values, and avoiding infinite loops if circular references exist. It’s a very common utility implementation in modern JavaScript development.
This relies on the Recursion and Type Checking pattern.
obj1 = { a: { b: 1 }, c: 2 }, obj2 = { a: { d: 3 }, e: 4 }
Be prepared to handle arrays. Some interviewers want arrays to be concatenated, others want them merged by index. Clarify the expected behavior for array conflicts early in the conversation.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Dota2 Senate | Medium | Solve | |
| String to Integer (atoi) | Medium | Solve | |
| 01 Matrix | Medium | Solve | |
| 132 Pattern | Medium | Solve | |
| 2 Keys Keyboard | Medium | Solve |