Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function that merges two deeply nested objects, combining properties without overwriting them.

Hard

Problem Statement

Write a function that merges two deeply nested objects, combining properties without overwriting them.

Sample Input

{ a: { b: 1, c: 2 } }, { a: { d: 3 } }

Sample Output

{ a: { b: 1, c: 2, d: 3 } }

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Merge two deeply nested objects without overwriting properties function deepMerge(obj1, obj2) { // Recursively merge each property of the objects } console.log(deepMerge({ a: { b: 1, c: 2 } }, { a: { d: 3 } }));
Log in or sign up to run or submit your code.Log inSign up
Input
{ a: { b: 1, c: 2 } }, { a: { d: 3 } }
Expected Output
{ a: { b: 1, c: 2, d: 3 } }