Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

Given two binary trees, the task is to find if both of them are identical or not.

**Example 1:**

**Input:
** 1 1
/ \ / \
2 3 2 3
**Output: **Yes**
Explanation: **There are two trees both
having 3 nodes and 2 edges, both trees
are identical having the root as 1,
left child of 1 is 2 and right child
of 1 is 3.

**Example 2:**

**Input:
** 1 1
/ \ / \
2 3 3 2
**Output: **No**
Explanation: **There are two trees both
having 3 nodes and 2 edges, but both
trees are not identical.

**Your task:**

Since this is a functional problem you don't have to worry about input, you just have to complete the function **isIdentical()** that takes two roots as parameters and returns true or false. The printing is done by the driver code.

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(Height of the Tree).

**Constraints:**

1 <= Number of nodes <= 1000

1 <=Data of a node <= 1000

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Determine if Two Trees are Identical

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.