Explain C++ vector, unordered_map, and virtual functions
Company: Jump Trading
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
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).
Quick Answer: This question evaluates knowledge of C++ container performance and memory semantics, hashing and collision handling in associative containers, and runtime polymorphism mechanics, specifically probing vector growth behavior, unordered_map internals, and virtual function dispatch.