core practice · coding problem

Non-overlapping Intervals

LeetCode #435 — Non-overlapping Intervals. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/non-overlapping-intervals/

The mechanism

Dynamic programming is recursion with the repeated work cached. Define the state (what does dp[i] mean?), the recurrence (how does dp[i] build on earlier states?), and the base case. 1D DP means the state is a single index along a sequence.

Study 1D DP

Expected evidence

Pass all LeetCode test cases for this problem.

Try this drill in the practice workspace →

Hints when you need them
  • Pattern hint: dp 1d.
  • Start with brute force, then optimize time/space.
  • Write down invariants before coding.

Watch for these mistakes

  • Starting to code before clearly defining what dp[i] represents
  • Wrong iteration order so a state is read before it is computed
  • Missing or wrong base cases

Check the sources

Practice the same mechanism

Browse all practice briefs