Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Increasing Order Search Tree
EASY
15 mins
4 upvotes
Trees
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Trees
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Increasing Order Search Tree

Contributed by
Prateek_18cb
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share
4 upvotes

Problem Statement

Ninja has been given a binary search tree. Ninja has to rearrange the tree such that:

1. The leftmost node of the binary search tree becomes the root of the tree.
2. Every node has no left child.
3. Every node has only one right child.
For example:

As Ninja is busy, he asks you for help. Can you help Ninja to rearrange the binary search tree?

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
1
2 1 3 -1 -1 -1 -1
Sample Output 1:
1 -1 2 -1 3 -1 -1
Explanation for Sample Output 1:
For sample test case 1: 

Sample Input 2:
1 
10 7 12 4 9 -1 -1 -1 -1 -1 -1
Sample Output 2:
4 -1 7 -1 9 -1 10 -1 12 -1 -1
Explanation for Sample Output 2:
For sample test case 1: 

Reset Code
Full screen
Auto
copy-code
Console