Implement a reference-counted smart pointer
Company: Aurora
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of C++ resource management, ownership semantics, RAII, and reference counting implementation within the coding and algorithms domain, emphasizing pointer semantics and object lifetime.
Examples
Input: ((('new', 'a', 'obj'), ('copy', 'b', 'a'), ('use_count', 'a'), ('reset', 'a'), ('use_count', 'b')),)
Expected Output: [2, 1]
Explanation: Copy increments and reset decrements.
Input: ((('new', 'a', 'x'), ('move', 'b', 'a'), ('get', 'a'), ('use_count', 'b')),)
Expected Output: [None, 1]
Explanation: Move leaves source null.
Input: ((('use_count', 'missing'),),)
Expected Output: [0]
Explanation: Null count is zero.
Hints
- A real C++ implementation stores a control block with pointer and count, incrementing on copy and decrementing on destruction/reset.