Problem, as an interviewer would state it:
"Write a function isCyclic(obj) that detects circular references anywhere in an object or array graph."
Examples:
const a = { name: "a" }; a.self = a;
isCyclic(a); // true
isCyclic({ x: { y: [1, 2] } }); // false
Clarifying questions expected:
- Is the same object appearing twice (but not inside itself) a cycle?
- Which structures must be traversed — plain objects and arrays only, or also
Map/Set? - How deep can the structure be, and does recursion depth matter?
Code / implementation expected: Yes — real, direct proof of a self-reference, an indirect cycle, an array cycle, and the shared-reference case that must NOT be reported.