#60 Finding Equivalent Subtrees by Letter Set
A rooted binary tree is given, and each vertex contains one letter from A-Z. Two vertices are considered equivalent
if the subtrees rooted at those vertices contain the same set of letters, without considering frequencies. Find any pair of equivalent vertices:
/*
A
/ \
C B
/ \ / \
A D A D
/ \
B C
*/
class TNode {
char value = '\0'; // [A-Z]
TNode left = null;
TNode right = null;
};
Pair<TNode, TNode> findEquivalentSubtrees(TNode root) {
...
}Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor