Unstop Coding Question – Solved

9 Live
Solution Rahul has an integer array called 'arr' of length N containing unique values. He wants to create a balanced tree where each parent node has smaller valued nodes on its left and larger valued nodes on its right. This balanced tree should ensure that the depth of the two subtrees for every node doesn't differ by more than one. Your task is to assist him in creating this type of tree. The output contains N lines denoting the pre-order traversal of nodes. If the left child of the node contains a non-null value, then print the value; otherwise, print a dot (.). A similar process for the right child also. Each right child value is separated from the node by a ">" sign, and each left child by a left arrow sign. Input Format: - First line contains an integer N representing the size of the array arr. - The second line contains N unique space-separated integers representing the elements of the array arr. Output Format: The output contains N lines denoting the pre-order traversal of nodes. If the left child of the node contains a non-null value, then print the value; otherwise, print a dot (.). A similar process for the right child also. Each right child value is separated from the node by a "-" sign, and each left child by a left arrow sign. Constraints: 1 <= N <= 10^5 1 <= arr[i] <= 10^19

Asked in: Unstop

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |