1D

1D Dynamic Programming

Fibonacci-style, house robber, climbing stairs, and linear DP patterns.

0 Problems3-4 hours

Overview

1D DP problems have a single state variable, usually dp[i] representing the answer for the first i elements. The recurrence typically looks at dp[i-1] or dp[i-2].

Complexity Summary

Time Complexity

O(n)

Space Complexity

O(n) reducible to O(1) for Fibonacci-like problems

Key Patterns & Techniques

Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.

1

Climbing stairs

Concept

dp[i] = dp[i-1] + dp[i-2]

2

House robber

Concept

dp[i] = max(dp[i-1], dp[i-2] + nums[i])

3

Min cost climbing

Concept

dp[i] = cost[i] + min(dp[i-1], dp[i-2])

4

Decode ways

Concept

dp[i] = dp[i-1] (if valid single) + dp[i-2] (if valid pair)

5

Max product subarray

Concept

track max and min due to sign flips

6

Coin change

Concept

dp[i] = min(dp[i - coin] + 1) for all coins

DSA Practice Online - 150+ Coding Interview Questions | LeetCode Alternative | InstaMock - AI Mock Interview