Mark As Completed Discussion

In this method, we will create an indexed table (2D array) having n rows and m columns where n and m are equal to the length of the string. You may wonder why we're using such a table.

Well, dynamic programming is about using solving sub-problems of a larger problems, and then using those results to avoid any repeat work. The shape of the two-dimensional array allows us to more intuitively hold solutions of subproblems. This will make more sense as we continue-- the table helps us easily model our findings thus far.

Efficient Solution

A sample 2-dimensional array syntax is as follows:

PYTHON
1array = [[...], [...], ..., [...]]

Let us revisit the string "maham". We'll create a table having rows and columns equal to the length of the string. This is 5 in our case.

Efficient Solution