Gyanthakur / LeetCode_potd

16 stars 34 forks source link

Create potd_24_10_2024.cpp #46

Open PriyanshK09 opened 8 hours ago

PriyanshK09 commented 8 hours ago

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:

By considering both cases, we ensure that we account for potential flips at every node.

Checklist

Additional Notes

Complexity Time complexity: $$O(n)$$ Space complexity: $$O(h)$$

Please add any other information that is relevant to this pull request, including potential risks, alternative solutions considered, or future improvements.