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

Programming Exercises

Write a function to perform a deep clone of an object.

Hard

Problem Statement

Write a function to perform a deep clone of an object.

Sample Input

{ name: "John", age: 30, details: { city: "New York", skills: ["TypeScript", "JavaScript"] } }

Sample Output

Original: {
  name: 'John',
  age: 30,
  details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}
Clone: {
  name: 'John',
  age: 30,
  details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
function deepClone<T>(obj: T): T { // Your logic here }
Log in or sign up to run or submit your code.Log inSign up
Input
{ name: "John", age: 30, details: { city: "New York", skills: ["TypeScript", "JavaScript"] } }
Expected Output
Original: {
  name: 'John',
  age: 30,
  details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}
Clone: {
  name: 'John',
  age: 30,
  details: { city: 'New York', skills: [ 'TypeScript', 'JavaScript' ] }
}