Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

maps-sets-intro

Maps and sets intro

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

An orientation to the C++ track—how the compiled playground works, core vocabulary, and what you will practice next.

You need a clear map of the C++ track so classes, RAII, templates, and the STL do not feel like magic.

You will apply Maps and sets intro in contexts like: Game engines, trading systems, desktop apps, and performance-critical libraries.

Write C++ in main.cpp with int main(), click Run on server—the dev runner compiles with c++/g++ -std=c++17 -Wall and runs the binary; read template errors in stderr (LEARNING_RUNNER_ENABLED=true). Also read the interview prep blocks.

After the C track or equivalent—C++ builds on C memory ideas and adds OOP, templates, and the STL.

Associative containers store keys efficiently. std::map holds sorted key-value pairs; std::set holds unique sorted keys.

map example

std::map<std::string, int> scores;
scores["ada"] = 100;
scores["linus"] = 95;

For frequent lookups without order requirement, std::unordered_map offers average O(1) hashing (also STL).

Important interview questions and answers

  1. Q: map vs unordered_map?
    A: map keeps keys sorted (tree); unordered_map uses hash table—pick based on ordering and performance needs.
  2. Q: operator[] on map?
    A: Inserts default-constructed value if key missing—use .at() or .find() when insert is undesired.

Self-check

  1. What does std::set guarantee about duplicates?
  2. When prefer unordered_map?

Pitfall: map[key] inserts default values—use .find() or .at() when insertion side effects are unwanted.

Interview prep

map vs unordered_map?

map keeps sorted keys (tree); unordered_map uses hashing for average O(1) lookup.

operator[] side effect?

Inserts default value if key missing—use .at() or .find() when insert is undesired.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • map vs unordered_map?
  • Key requirements?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump