« Previous
Next »
Summary
Wrapping up the DSA track with what you can solve and where to push next.
What you learned + LRU cache
EXAMPLE
# DSA summary
You can now:
- Read a problem and recognise the underlying pattern
- Walk through brute force + complexity before coding
- Apply two pointers, sliding window, prefix sums on arrays
- Use hashing for set/dedup/index problems
- Traverse trees and graphs (BFS/DFS) and choose the right one
- Use union-find for connectivity problems
- Apply 1D and 2D dynamic programming when overlapping subproblems show up
- Reason about heaps for top-K and merge-K
- Design simple systems: LRU cache, rate limiter, mini scheduler
# Your next step - an LRU cache in TypeScript
class LRU<K, V> {
private map = new Map<K, V>();
constructor(private capacity: number) {}
get(key: K): V | undefined {
if (!this.map.has(key)) return undefined;
const value = this.map.get(key)!;
this.map.delete(key);
this.map.set(key, value); // move to end (most recent)
return value;
}
set(key: K, value: V): void {
if (this.map.has(key)) this.map.delete(key);
else if (this.map.size >= this.capacity) {
const first = this.map.keys().next().value;
this.map.delete(first); // evict oldest
}
this.map.set(key, value);
}
}
Why it matters
Patterns transfer. Memorising 300 problems does not. If you can articulate which pattern fits before you code, you have the skill the interviews are really testing.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
// Next: segment trees, persistent data structures, advanced graph algos, competitive programming.Try it Yourself »
« Previous
Next »
Discussion
Loading…