Skip to content

Instantly share code, notes, and snippets.

@mheuser
Created December 12, 2012 01:39
Show Gist options
  • Save mheuser/4264109 to your computer and use it in GitHub Desktop.
Save mheuser/4264109 to your computer and use it in GitHub Desktop.
getMaxWithAndMaxDepth = (root, depth=0, depthToWidth=[])->
if !depthToWidth[depth] then depthToWidth[depth] = 0
depthToWidth[depth] += root.children.length
getMaxWithAndMaxDepth child, depth+1, depthToWidth for child in root.children
maxDepth = depthToWidth.length
maxWidth = _.max depthToWidth
{maxWidth, maxDepth}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment