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 ), 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.