Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

p =
q =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Two trees are the same if roots match and left/right subtrees are the same.

Approach

DFS simultaneously. If both nodes are null, true. If one null or values differ, false.

Why it works

Structural equality and value equality must hold at every corresponding node.

Code
Loading...
Complexity
Time: O(n)
Space: O(h)
Solution
Updated: 2026-02-23

Idea

Two trees are the same if roots match and left/right subtrees are the same.

Approach

DFS simultaneously. If both nodes are null, true. If one null or values differ, false.

Why it works

Structural equality and value equality must hold at every corresponding node.

Code
Loading...
Complexity
Time: O(n)
Space: O(h)