Explain C++ vector, unordered_map, and virtual functions
Jump TradingSoftware Engineer · Technical ScreenLast updated
Explain C++ vector, unordered_map, and virtual functions evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
In C++, explain:
- The amortized and worst-case time complexity of vector::push_back, and how capacity growth/expansion is implemented (growth factor, reallocation steps, move vs. copy semantics, and iterator/reference invalidation rules).
- How unordered_map is implemented under the hood: hashing function usage, bucket array layout, collision handling (e.g., chaining), load factor thresholds, rehashing strategy, iterator/reference invalidation, and expected time complexity guarantees for insert/find/erase.
- The purpose of virtual functions, how dynamic dispatch works (vtables/vptr), associated runtime and memory costs, when virtual destructors are needed, and trade-offs versus alternatives (templates, static polymorphism).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.