Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Same Tree

Easy
treebinary-treedfs

Given two binary trees p and q, return true if they are structurally identical with equal values.

Input

  • Line 1: tree p in level order
  • Line 2: tree q in level order

Output: true or false.

Example 1
Input:
1 2 3
1 2 3
Output:
true
Example 2
Input:
1 2
1 null 2
Output:
false
Example 3
Input:
1 2 1
1 1 2
Output:
false

Constraints

  • 0 ≤ nodes ≤ 100 per tree
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.