A
Anonymous

Login Page - Copy this React, Tailwind Component to your project

Given two array's of same size N, construct two binary tree's from two array's. Then find if the leaf nodes of two trees are in same order or not. The representation of tree in array A is as follows Indexes of array are values present in the tree nodes The value A[i] present at index i, is the parent of node with value i A[i] is parent of i For the root node, the value of index would be " 1" Example: Array A = [5, 7, 1. 5, 7, 2, 3, 2, 4] Tree constructed from above array 2 / \ 5 7 / \ / \ 0 3 1 4 / / 6 8 Explanation: Array: [5, 7, 1, 5, 7, 2, 3, 2, 4] Index: [0, 1, 2, 3, 4, 5, 6, 7, 8] 1 is present at index 2, so 2 is the root node 2 is present at index 5 and 7. So 5 and 7 are left and right children of node 2 5 is present at index 0 and 3. So 0 and 3 are left and right children of node 5 3 is present at index 6. So 6 is the left child of node 3 And rest of the tree is represented in same way After tree is constructed, find the leaf nodes of the tree. A leaf node is the node which does not have any children. For the tree represented above, the leaf nodes are 0, 6, 1 and 8. Construct two trees from two given arrays, find leaf nodes of two trees. If the order of leaf nodes of two trees is same, then print the order of leaf nodes, else print No Input Format First line contains a number N, which is the size of array Next two lines contains N space separated numbers to make up the arrays Constraints 0 < n <= 100 Output Format Print the order of leaf nodes as space separated numbers, if leaf nodes of two tree's are in same order. If leaf nodes of two tree's are not in same order, then print No Sample Input 0 9 5 7 1 5 7 2 3 2 4 4 2 5 1 3 3 4 5 7 Sample Output 0 0 6 1 8 Sample Input 1 3 1 0 0 1 1 1 Sample Output 1 No

Prompt
Component Preview

About

LoginPage - A sleek, responsive login interface built with React and Tailwind. Features include user-friendly design, validation, and. Download code free!

Share

Last updated 1 month ago