Same Tree

Try to solve the Same Tree problem.


Given the roots of two binary trees, p and q, write a function to check whether or not they are the same. Two binary trees are considered the same if they’re structurally identical and the nodes have the same value.


  • The number of nodes in the tree is in the range [0,100][0, 100]

  • 104-10^4 \leq 104\leq 10^4


Level up your interview prep. Join Educative to access 80+ hands-on prep courses.