This article is not meant to introduce more advanced concepts like dynamic programming. Instead, it will introduce the mentality required to start solving recursive problems.

The examples are in Javascript, but I’ll write answers in Python and C++ in the bottom of this article.

What is recursion

Since you are reading this article, I’m assume that you have a vague idea of recursion, so I won’t go deep into the context of it. Personally, I like to think of recursion as the following.

Recursion is a way to solve a problem by solving smaller subproblems.