Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem of the Day (October 24)
Description
Please include a summary of the changes and the related issue(s) this pull request addresses. Include any relevant context or background information.
The problem asks whether two binary trees are flip equivalent. Two trees are flip equivalent if they are the same when flipped at any node, meaning that at any node, we can swap the left and right subtrees.
My first thought is that we need to check the values of the nodes in a recursive manner. At each node, we either check if both left and right subtrees are the same without flipping, or we check if they are the same with flipping (i.e., left subtree of one tree corresponds to the right subtree of the other and vice versa).
Fixes: #45 (replace with the issue number, if applicable)
Use [x] to represent a checked (ticked) box.✅
Use [ ] to represent an unchecked box.❌
Type of Change
How to Test
We can solve this using recursion. At each step:
- If both nodes are NULL, they are trivially equivalent.
- If only one of them is NULL or their values are different, they cannot be flip equivalent.
By considering both cases, we ensure that we account for potential flips at every node.
Checklist
Additional Notes
Complexity$$O(n)$$ $$O(h)$$
Time complexity:
Space complexity:
Please add any other information that is relevant to this pull request, including potential risks, alternative solutions considered, or future improvements.