The question asked in every other C++ interview, because the interviewer was once asked it too: 'implement a dynamic array'. They won't be watching whether push_back works — they'll be watching what happens on copy and whether you call destructors. A little part of them dies every time a candidate reaches for realloc.
Implement Vector<T> — a growable array like std::vector, with amortised O(1) push_back via geometric capacity growth.
push_back appends; capacity must grow geometrically (e.g. double)size() is the element count, capacity() the allocated slotsoperator[] gives read/write accesspush_back O(1) amortised?When size == capacity, allocate a new array of capacity * 2 (or 1 if empty) and copy elements over.
Doubling keeps push_back amortised O(1); growing by one would be O(n²) total.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.