Ninja Training

Problem

Intuition

Code

Top Down - Memoization

circle-info

Time Complexity:O(N*4*3)

N -> Total Number of days

4 -> 4 states (3 activities + 1)

N*4 -> For filling the 2D dp array with "-1"

3 -> Iterating it 3 times over all activities as we need to figure out all the possibilities

Space Complexity: O(N)

O(N*4) -> DP array = O(N)

O(N) -> Recursion stack space = O(N)

Finally, O(N) + O(N) = O(2N) = O(N)

Bottom Up

circle-info

Time Complexity:O(N*4*3)

N -> Total Number of days

4 -> 4 states (3 activities + 1)

N*4 -> For filling the 2D dp array with "-1"

3 -> Iterating it 3 times over all activities as we need to figure out all the possibilities

Space Complexity: O(N)

O(N*4) -> DP array = O(N)

O(N) -> Recursion stack space = O(N)

Finally, O(N) + O(N) = O(2N) = O(N)

Last updated