Skip to content

Instantly share code, notes, and snippets.

@BriceShatzer
Last active August 28, 2022 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BriceShatzer/38dd57d362598e7d47a3cd093adb3306 to your computer and use it in GitHub Desktop.
Save BriceShatzer/38dd57d362598e7d47a3cd093adb3306 to your computer and use it in GitHub Desktop.

Suppose you're given a binary tree represented as an array. For example, [3,6,2,9,-1,10] represents the following binary tree (where -1 is a non-existent node):

enter image description here

Write a function that determines whether the left or right branch of the tree is larger. The size of each branch is the sum of the node values. The function should return the string "Right" if the right side is larger and "Left" if the left side is larger. If the tree has 0 nodes or if the size of the branches are equal, return the empty string.

Example Input:

[3,6,2,9,-1,10] 

Example Output:

Left

test cases: 
[3,6,2,9,-1,10] = "left"  
[1,4,100,5] = "right"  
[1,10,5,1,0,6] = ""  
[] = ""  
[1] = ""  

Shouldn't that answer to the example be "" because it's balanced?

@BriceShatzer
Copy link
Author

BriceShatzer commented Apr 13, 2020

yep I was counting the nodes rather than the values of the nodes.
Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment