The solution in Google+ needs to take the logarithm, and that is O(n) in many implementation including the Google+ solution.
I'm highly inspired by the rest of the argument though. Anyway, my addition: if you allow "0" as a an element of the tree, then you always have a complete binary tree, e.g. 4 -> 2, 1 -> 1, 0, 0, 0 There is a nice property also: "sum of numbers in a level + cardinality of level" is a constant, including the terminal level. i.e. 4 + 1 = (2+1) + 2 = (1+0+0+0) + 4 -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/c26c620d-a73d-444a-a6e0-238eeb6241de%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.