donnemartin / interactive-coding-challenges

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
Other
29.44k stars 4.45k forks source link

Change bottom up implementation #229

Open rodferro opened 6 years ago

rodferro commented 6 years ago

Inputs don't need to be sorted, but we have to change how the bottom up implementation populates the results array.

We can also simplify some of the statements by:

1) removing the call to list when we create the list 'items', as there's no need for it; 2) initializing the list items with zeros; and 3) removing the if statement in the nested loop, since it's not necessary anymore because of no. 2.

We have to change the test too. We can't hardcode the labels to indices because they may be in a different position.