Rs
All modules
04
Intermediate · 8 submodules · 23 lessons · 7h 56m

Data Structures for Interviews

Interview toolkit in proper order: arrays/Vec, stdin parsing, HashMap ops, sets, sorting, stack/queue/deque, priority queues, and classic patterns.

Submodule 4.1

Arrays & Vec

Fixed arrays, dynamic Vec, indexing, and common interview ops.

  1. 1

    Fixed Arrays [T; N]

    Stack arrays, length in the type, and when interviews still use them.

    18 min
  2. 2

    Vec Interview Operations

    push, pop, insert, remove, get, len, is_empty, clear — complexity and patterns.

    22 min
  3. 3

    Slices, windows & iteration patterns

    Subarrays as slices, windows for pairs, enumerate for indices.

    20 min

Submodule 4.2

Reading Input (stdin)

Ints, strings, multi-line input — competitive programming & interview I/O.

  1. 1

    stdin Basics: lines & tokens

    read_line, split_whitespace, parse — real stdin vs playground simulation.

    22 min
  2. 2

    Common Input Patterns

    n then n lines; n m grid; until EOF; strings with spaces.

    24 min
  3. 3

    Real stdin API (copy-paste for local)

    io::stdin, BufRead, fast-ish patterns you will use in contests.

    16 min

Submodule 4.3

HashMap: Add, Get, Remove

The interview map — insert, update, remove, entry API, frequency maps.

  1. 1

    HashMap Insert, Get, Update

    insert, get, get_mut, contains_key — and owned String keys.

    22 min
  2. 2

    Remove, retain, drain, clear

    remove returns old value; retain filters; clear empties.

    18 min
  3. 3

    Frequency Maps (classic)

    Count characters/words; two-sum with HashMap; anagram check.

    22 min

Submodule 4.4

Sets: HashSet & BTreeSet

Membership, uniqueness, intersection-style problems.

  1. 1

    HashSet Insert, Contains, Remove

    Unique elements, O(1) membership tests.

    20 min
  2. 2

    BTreeSet Ordered Uniques

    Sorted unique keys; first/last; range queries mindset.

    18 min

Submodule 4.5

Sorting & Custom Comparators

sort, sort_by, sort_by_key, reverse, stable thinking for interviews.

  1. 1

    sort, reverse, binary_search

    In-place sort on Vec; reverse; binary_search API.

    20 min
  2. 2

    Custom Sorting: sort_by & sort_by_key

    Sort pairs, strings by length, structs by field — interview gold.

    24 min
  3. 3

    Sorting Structs & Argsort

    Derive Ord or custom; indices argsort pattern.

    18 min

Submodule 4.6

Stack, Queue & Deque

Vec as stack; VecDeque as queue and deque.

  1. 1

    Stack with Vec

    push/pop back; valid parentheses; monotonic stack intro.

    18 min
  2. 2

    Queue with VecDeque

    push_back + pop_front; BFS-ready queue.

    20 min
  3. 3

    Deque: Both Ends & Sliding Window

    push/pop front and back; monotonic deque for sliding window max.

    24 min

Submodule 4.7

Priority Queue (BinaryHeap)

Max-heap by default; min-heap with Reverse; top-k patterns.

  1. 1

    BinaryHeap Max-Heap

    push, pop, peek — largest first.

    20 min
  2. 2

    Min-Heap with Reverse

    std::cmp::Reverse wrapper — critical interview trick in Rust.

    20 min
  3. 3

    Heap Task: Meeting Rooms / Free Times

    Sort intervals + min-heap of end times — classic interview combo.

    22 min

Submodule 4.8

Interview Patterns Lab

Wire structures together on classic problems.

  1. 1

    Structure Cheat Sheet

    Which structure for which problem — memorize this table.

    15 min
  2. 2

    Lab: LRU Cache Sketch (HashMap + order)

    Interview favorite: O(1) get/put mental model; implement a simple O(n) version then discuss O(1).

    28 min
  3. 3

    Lab: End-to-End Mini Problem

    Parse input, count with map, sort top frequencies, use heap optional.

    25 min