Chapter 11
These are the solutions to the exercises found in the section Exercises.
-
Let’s call our function character_count. The first step is to pretend that the character_count function has already been implemented.
Next, we need to identify the subproblem. If our problem is the array ["ab", "c", "def", "ghij"], then our subproblem can be the same array missing one string. Let’s specifically say that our subproblem is the array minus the first string, which would be ["c", "def", "ghij"].
Now, let’s see what happens when we apply the “already-implemented” function on the subproblem. If we were to call character_count(["c", "def", "ghij"]), we’d get a return value of 8, since there are eight characters in total.
So to solve our original problem, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access