DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Tree

Same Tree

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Same Tree** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Recursive structural + value comparison **Edge Cases to Consider:** - (1) Both null (true) - (2) One null, other not - (3) Same structure, different values

Examples

Example 1
Input: [1,2,3], [1,2,3]
Output: true
Explanation: Identical
Example 2
Input: [1,2], [1,null,2]
Output: false
Explanation: Different structure
Example 3
Input: [1,2,1], [1,1,2]
Output: false
Explanation: Same structure, different values

Constraints

  • ▪The number of nodes in the tree is in the range [0, 2000]
  • ▪-1000 <= Node.val <= 1000
  • ▪Ensure depth-first or breadth-first traversals are memory-efficient

Watch Out For Edge Cases

  • ▪Both null (true)
  • ▪One null, other not
  • ▪Same structure, different values
Frequently Asked At
AmazonMicrosoftAdobeTCS