Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6454 |

@blackshadows | 6380 |

@mb1973 | 5718 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3709 |

@mantu_singh | 3556 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1285 |

@gurshehzadsingh | 1052 |

@pritsahkar2000 | 812 |

@satyamchhatrala | 806 |

@nithinreddy3210 | 801 |

@iib2019024 | 745 |

@mohanreddy8847 | 704 |

@iamchaitanyahegde | 662 |

@shafeeq3543 | 651 |

@workit | 646 |

@AkashLahoty | 642 |

Complete Leaderboard |

Given a Linked List Representation of Complete Binary Tree. The task is to construct the Binary tree.

**Note : **The complete binary tree is represented as a linked list in a way where if root node is stored at position i, its left, and right children are stored at position **2*i+1**, **2*i+2** respectively.

**Example 1:**

**Input:
**N = 5
K = 1->2->3->4->5
**Output: **1 2 3 4 5**
Explanation: **The tree would look like
1
/ \
2 3
/ \
4 5
Now, the level order traversal of
the above tree is 1 2 3 4 5.

**Example 2:**

Input:N = 5 K = 5->4->3->2->1Output:5 4 3 2 1Explanation:The tree would look like 5 / \ 4 3 / \ 2 1 Now, the level order traversal of the above tree is 5 4 3 2 1.

**Your Task:**

The task is to complete the function **convert**() which takes head of linked list and **root **of the tree as the reference. The driver code prints the level order.

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(H).

**Note: **H is the height of the tree and this space is used implicitly for recursion stack.

**Constraints:**

1 <= N <= 10^{5}

1 <= K_{i} <= 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?

YesLoading...

Make Binary Tree From Linked List

...