Verily Interview Question

recursion / iteration, tree, design question