Question bank › Hashing
Dsa Hashing Medium

The Code Clone Detector

You are analyzing a program's abstract syntax tree. Each node in the tree has a string value and zero or more children. Two subtrees are considered 'clones' if they have the exact same structure and the same values at every corresponding node. Given a tree, count how many nodes are the root of a subtree that has at least one other identical clone elsewhere in the tree. Input Format: - Line 1: N, the number of nodes (labeled 0 to N-1). - Next N lines: Each line describes a node: `node_id value child_count [child_id1 child_id2 ...]` Output Format: - An integer representing the count of nodes whose subtrees are not unique. Example: Input: 3 0 Root 2 1 2 1 Leaf 0 2 Leaf 0 Output: 2 (Explanation: Node 1 and Node 2 both root the same subtree 'Leaf', so both are counted.)

Key concepts

hashingtreesrecursion

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.