Lesson 8 of 8Article25 min
Project: Problem Solving Toolkit
Build a mini toolkit that can run multiple DSA helpers: palindrome check, BFS shortest path, and top-K frequent elements. The focus is selecting the correct data structure per task.
Project goal
Build a mini toolkit that can run multiple DSA helpers: palindrome check, BFS shortest path, and top-K frequent elements. The focus is selecting the correct data structure per task.
- Input parser and test runner.
- Pattern tagging: array, graph, heap, tree.
- Time/space complexity notes for each function.
Top-K frequent example
Extension: replace sorting with a heap for better performance when k << n.
Frequency map + sorting baseline
function topKFrequent(nums: number[], k: number): number[] {
const freq = new Map<number, number>();
for (const n of nums) freq.set(n, (freq.get(n) ?? 0) + 1);
return [...freq.entries()]
.sort((a, b) => b[1] - a[1])
.slice(0, k)
.map(([value]) => value);
}