PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • hard
  • Aurora
  • Coding & Algorithms
  • Software Engineer

Implement a reference-counted smart pointer

Company: Aurora

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Implement a minimal C++ reference-counted smart pointer similar to `std::shared_ptr`. Requirements: - Create a class template `SharedPtr<T>` that manages a heap-allocated `T*`. - Use RAII: the managed object must be deleted exactly once when the last `SharedPtr` owning it is destroyed. - Support: - Default constructor (null pointer) - Constructor from raw pointer `T*` - Destructor - Copy constructor / copy assignment (increase reference count) - Move constructor / move assignment (transfer ownership, leaving the source null) - `T& operator*()`, `T* operator->()`, `T* get() const` - `size_t use_count() const` - `void reset(T* p = nullptr)` - Handle self-assignment correctly and avoid memory leaks/double-free. You may ignore thread-safety unless you explicitly choose to support it.

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.

Simulate SharedPtr ownership operations and return use_count/get query outputs.

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

  1. A real C++ implementation stores a control block with pointer and count, incrementing on copy and decrementing on destruction/reset.
Last updated: Jun 27, 2026

Related Coding Questions

  • Compute streaming sliding-window minimums - Aurora (medium)
  • Find viewing direction that sees most points - Aurora (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.