Skip to content

Instantly share code, notes, and snippets.

View razniceguy's full-sized avatar

Rajesh Pandian razniceguy

View GitHub Profile
@razniceguy
razniceguy / binary-tree-from-arrays.js
Created December 8, 2021 02:41
Creates a binary tree from one dimensional array and checks the largest branch from the root recursively.
function getSolution(arr) {
if (Array.isArray(arr)) {
if (arr.length <= 1) {
return '';
} else {
const left = getSumOfBranch(arr, 2);
const right = getSumOfBranch(arr, 3);
return (left === right) ? '' : ((left > right) ? 'Left' : 'Right')
}
} else {