Grokking Dynamic Programming Patterns for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
The runtime for brute force seems wrong. In general top down runtime can be infe...

Shan

Sep 2, 2022

The runtime for brute force seems wrong. In general top down runtime can be inferred by "the branching factor raise to the height of the recursion tree.

For the fibonacci its 2^n because at every point there are 2 decisions i.e. f(n-1) and f(n-2) hence 2^n is accurate.

For this problem the branching factor is not 2. Instead it should be the max(end - start) because that is the recursive call that will trigger the most subcalls. But keep in mind we limit our while loop to not exceed the size of the array to avoid going out of bounds. So the runtime should be O(len(jumps)^n) i.e. [100,1,0,2] would mean in the first call of the recursive methods we would trigger recursion 3 times therefore n-1 resolves to n because we can drop the constant.

2

0

Comments
Comments

On this page