Compute nested depth-weighted sum | Meta Interview Question