🎁 Exclusive Offer! Join our Telegram Channel to get **special discounts** and updates! 🚀

🚀 Struggling with coding interviews? We've got you covered! 💡 Practice real questions, sharpen your skills, and land your dream job! 🎯
Question 36 - 100% Working Solution | Buy Now

Description

7 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