recursively solve Max Depth