bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch
🌱Newbie
0 XP
Back to starter track
✏️Fill the BlankjavascriptEasy1-D Dynamic Programming

Starter: handle the smallest case

Fill the answer for an empty list. Goal: Return immediately when there are no items to count.

Starter step 3 of 20Read code one line at a time

Notice the simple case before the loop starts.

The blank should match the smallest answer the function can return directly.

Problem Brief

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Puzzle Hints
  1. Read the blank inside this exact statement: "return ___;".

  2. Before a loop runs, the smallest count is zero. The correct token works because it preserves the goal: Return immediately when there are no items to count.

  3. Check the variable that is read immediately after the blank; that usually tells you what the blank must produce.

Asked at 20 companies
AdobeAlibabaAmazon
How to think: Dynamic Programmingguide

The problem has overlapping subproblems and optimal substructure — "the answer at step N depends on previous steps."

1.Step 1: Define the state — "what does dp[i] represent?"
2.Step 2: Find the recurrence — "how does dp[i] depend on previous values?"
3.Step 3: Identify base cases — "what are dp[0], dp[1]?"
4.Step 4: Decide direction — bottom-up (iterative) or top-down (memoized recursion)
5.Step 5: Optimize space — do you need the whole array or just the last 1-2 values?

vs Greedy: Greedy makes locally optimal choices. DP tries all choices and picks the best.

vs Recursion without memoization: Plain recursion recomputes subproblems. Memoization caches them.

minimum costnumber of wayslongest subsequencecan you reachmaximum profitcoin change
How to think: Dynamic Programmingguide

The problem has overlapping subproblems and optimal substructure — "the answer at step N depends on previous steps."

1.Step 1: Define the state — "what does dp[i] represent?"
2.Step 2: Find the recurrence — "how does dp[i] depend on previous values?"
3.Step 3: Identify base cases — "what are dp[0], dp[1]?"
4.Step 4: Decide direction — bottom-up (iterative) or top-down (memoized recursion)
5.Step 5: Optimize space — do you need the whole array or just the last 1-2 values?

vs Greedy: Greedy makes locally optimal choices. DP tries all choices and picks the best.

vs Recursion without memoization: Plain recursion recomputes subproblems. Memoization caches them.

minimum costnumber of wayslongest subsequencecan you reachmaximum profitcoin change

Drag tokens into the blanks

0
1
1// Goal: Return immediately when there are no items to count.
2function starterExample() {
3 if (items.length === 0) {
4 return ___;
5 }
6}