Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5578 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 714 |

@Manikanta punnam | 579 |

@sriramgoparaju99 | 532 |

@yashkaril4 | 517 |

@praveenbgp6 | 517 |

@prankursharma31 | 489 |

@rdakka | 465 |

@sonamnigam1999 | 441 |

@purohitmn02 | 427 |

@sonamkumari63928 | 426 |

@ShubhankarPandey | 419 |

Complete Leaderboard |

Given two **n**-ary trees. Check if they are mirror images of each other or not. You are also given **e** denoting the number of edges in both trees, and two arrays, **A[] **and** ****B[]**. Each array has 2*e space separated values u,v denoting an edge from u to v for the both trees.

**Example 1:**

Input:n =3,e =2A[] ={1, 2, 1, 3}B[] ={1, 3, 1, 2}Output:1Explanation:1 1 / \ / \ 2 3 3 2 As we can clearly see, the second tree is mirror image of the first.

**Example 2:**

Input:n =3,e =2A[] ={1, 2, 1, 3}B[] ={1, 2, 1, 3}Output:1Explanation:1 1 / \ / \ 2 3 2 3 As we can clearly see, the second tree isn't mirror image of the first.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **checkMirrorTree()** which takes 2 Integers n, and e; and two arrays A[] and B[] of size 2*e as input and returns 1 if the trees are mirror images of each other and 0 if not.

**Expected Time Complexity:** O(n)

**Expected Auxiliary Space:** O(n)

**Constraints:**

1 <= n,e <= 10^{5}

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
Check Mirror in N-ary tree

...