All problems
Union by Size Height Bound
Problem
With union by size and no path compression, a tree with k nodes has height at most floor(log2 k). Return the maximum possible height in edges for a forest of n nodes, and 0 when n <= 1.
Hint
A tree of height h needs at least 2^h nodes because each level doubles the subtree size.
Test cases
case 1
in: [1]
expected: 0
case 2
in: [2]
expected: 1
case 3
in: [4]
expected: 2
case 4
in: [100]
expected: 6
case 5
in: [0]
expected: 0
Starter codePython
def union_by_size_height(n):
# Your code here
pass5 test cases · run your code against them in the editor