January 2018
Intermediate to advanced
332 pages
7h 36m
English
In this example, for this type of problem, we will be creating a two-dimensional array, where one dimension, (y), represents the values of the elements (that is, costs of each expense: 5, 3, 2, 2, and 5) and the other dimension, (x), represents the total cost incrementally (that is, 0 through 10). This is why we normalize our data in the first step—it helps us in terms of keeping our array small in terms of its dimensions.
Once we have the array, we will assign each of the array positions—arr[i][j]—as true if any of the 0 to i costs can create the j sum at any point, else it will be false:
CREATE empty 2d array with based on input dataIF expected total 0, any element can achieve this, so set [i][0] to trueIF cost of first row ...
Read now
Unlock full access