I’ve found an ATM analogy answering what recursion is in this video.

This analogy may help you to solve leetcode #104 Maximum Depth of Binary Tree. All you need is to imagine that you have multiple ATMs and need to choose a max path:

public int MaxDepth(TreeNode root)
if (root == null)
return 0;

var left = 1 + MaxDepth(root.left);
var right = 1 + MaxDepth(root.right);

return Math.Max(left, right);

As for me, it’s a simple analogy helping to remember the recursive approach for solving this problem.

Andrei Kruglov

Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store