Rs
Module 4Interview Patterns LabLesson 21 of 2315 min

Structure Cheat Sheet

Which structure for which problem — memorize this table.

Pick the right tool

Problem need Structure
-------------- -----------
Dynamic list / two pointers Vec / slice
Fast key → value HashMap
Unique / visited HashSet
Sorted unique / min-max keys BTreeSet / BTreeMap
LIFO Vec stack
FIFO / BFS VecDeque
Both ends / sliding window VecDeque
Repeated best element BinaryHeap
Top-k / min-heap BinaryHeap<Reverse<_>>
Custom order sort_by / sort_by_key

Always clarify

Constraints (n size), duplicates, sorted input, online vs offline.

Challenge

Add 3 more rows for your weakest topics.

Tips
  • Map problem → structure
  • State complexity
  • Practice under time

Try it live

Structure Cheat SheetRust 2021
Loading editor…
Output
Press Run to compile and execute.