Question bank › Trees
Dsa Trees Medium

The Equitable Grove

A subtree is 'Equitable' if it contains an equal number of even-valued nodes and odd-valued nodes. Given a tree, find the number of nodes in the largest Equitable subtree. If no such subtree exists, output 0. Input Format: - Line 1: N. - Line 2: N integers (values of nodes 0 to N-1). - Next N-1 lines: u v (edges, node 0 is root). Output Format: - The size (count of nodes) of the largest Equitable subtree. Example: Input: 6 1 2 3 4 5 6 0 1 0 2 1 3 1 4 2 5 Output: 6 Explanation: Root 0 has nodes {1,2,3,4,5,6}. Evens: 3, Odds: 3. Size 6.

Key concepts

treesubtreecounting

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.