Same Tree
A easy-tier problem at 65% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at Bloomberg and 10 others.
Same Tree gets asked at Bloomberg, Google, Amazon, and Microsoft. It looks easy on the surface, and the 65% acceptance rate proves most candidates solve it. But the trap is subtle: you need to handle null cases correctly, and the comparison logic has to be airtight. If you blank on the structure during your live assessment, StealthCoder reads your problem and surfaces a working solution in seconds, invisible to the proctor. This is the problem where overconfidence costs you 10 minutes you don't have.
Companies that ask "Same Tree"
Same Tree is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe core pattern is recursive comparison: check if both nodes match, then recurse left and right. Where candidates slip up is mixing their null-checking logic. You can't just compare values and assume structure. Both trees have to be identical in shape and content. DFS and BFS both work here, but DFS is the cleaner path. Most people get this right in practice, but in a live OA when you're under pressure and scanning code fast, you mishandle the base cases. StealthCoder is your hedge if the tree comparison semantics fuzzy up on the fly.
Pattern tags
You know the problem.
Make sure you actually pass it.
Same Tree recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Same Tree interview FAQ
Why does Same Tree feel easy but trip people up in real interviews?+
It IS easy conceptually, but null-handling and edge cases are where the actual thinking happens. You need to verify structure and values simultaneously. Most candidates code the happy path and miss the case where one subtree is null and the other isn't. That one mistake costs you the problem.
Is Same Tree still asked at FAANG companies?+
Yes. Bloomberg, Google, Amazon, Microsoft, and Apple all report asking it. It's a screening filter. Companies use it to see if you can reason about tree traversal without getting tangled in null pointers and recursion stack.
Should I use DFS or BFS for this problem?+
DFS is simpler. Recursion maps directly to the problem structure. BFS works but adds queue overhead for no real win here. Both are correct, but DFS lets you code it in 15 lines with no extra space.
What's the actual trick to Same Tree?+
There isn't one. That's what makes it dangerous. You can't overthink it or look for a clever trick. Just compare nodes recursively: check if values match, recurse left, recurse right. The trick is knowing there is no trick and nailing the implementation.
How does Same Tree relate to other tree problems I should know?+
It's foundational. It teaches you tree traversal pattern and null-safe comparisons. You'll see the same structure in Symmetric Tree, Invert Tree, and merge operations. Master this one and those become obvious.
Want the actual problem statement? View "Same Tree" on LeetCode →