Dynamic Programming21 sections · 916 units
Open in Course

Lessons from Boredom and Consecutive Subsequence

Patterns from both problems

Key takeaways from solving Boredom and Consecutive Subsequence.

From Boredom, you learned: When elements repeat, count frequencies first. Use cnt[v] to track how many times each value appears. Instead of processing each element, you process each unique value.

From Consecutive Subsequence, you learned: When values are huge (like 10910^9), arrays won't work. Use maps. Only store states for values that appear. This is state compression in action.

From both problems, remember: Always plan for reconstruction from the start. Add last_pos[v], prev[i], and best_end early. It's much harder to add them later. And don't forget: the four-step pattern (state, transition, base cases, answer) works everywhere.