const tree = [5, 8, 9, null, null, 7, 6, null, null, null, null, 3, 2, 4, 5] function getMinValue(tree) { let minValuePath = [] function getTree(index, path) { if (tree[index] == null) { return } path.push(tree[index]) if(index === 1 ||tree[index] < minValuePath[minValuePath.length-1]){ minValuePath = path } getTree(2 * index + 1, [...path]) getTree(2 * index + 2, [...path]) } getTree(0, []) return minValuePath } console.log(getMinValue(tree))