Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

root =
subRoot =

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

A tree subRoot is a subtree of root if some node in root starts an identical tree.

Approach

Traverse root. At each node, run a sameTree check against subRoot. If any match, return true.

Why it works

Every possible subtree root in root is examined; equality check ensures exact structural/value match.

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

Idea

A tree subRoot is a subtree of root if some node in root starts an identical tree.

Approach

Traverse root. At each node, run a sameTree check against subRoot. If any match, return true.

Why it works

Every possible subtree root in root is examined; equality check ensures exact structural/value match.

Code
Loading...
Complexity
Time: O(n*m) worst-case
Space: O(h)