Your question is Deep Clone Utility Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Cashfree Checkout configuration objects can contain nested dictionaries and lists. Implement a utility that creates a fully independent deep clone, so changing the clone never changes the original configuration.
Your function must also preserve reference relationships. If two properties in the input point to the same nested object, the corresponding properties in the clone must point to the same cloned object. Cyclic dictionaries or lists must not cause infinite recursion.
Implement deep_clone(value), where value is a JSON-like Python value composed of dictionaries with string keys, lists, and primitive values: None, booleans, integers, floats, and strings. Return a cloned value with the same structure and values.
Primitive values may be reused. Every dictionary and list must be newly allocated. The input must not be modified. Use an identity-based memoization map to handle repeated references and cycles.
def deep_clone(value):