Challenge: Create a Complete Binary Tree

Let’s create a complete binary tree.

Problem

Create a complete binary tree from values given as an array. A complete binary tree is such a tree in which every level except the last is filled.

Input

An integer array.

Output

A complete binary tree.

Sample input

arr := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Sample output

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.