Logo

Coding preview

Implement shared_ptr

What this preview is

About this preview

Implement shared_ptr is a medium quant coding problem on language knowledge in Cpp, asked at Quant.

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.

Implementing a thread-safe shared_ptr from scratch

This is a medium-difficulty C++ implementation problem common at quant trading firms, where deep knowledge of memory management and concurrency is essential. It tests whether you can build a reference-counted smart pointer that handles ownership transfer, lifetime management, and thread safety all at once.

The core challenge is designing a control block that tracks how many pointers own the same object, ensuring that the object is destroyed only when the last owner releases it. You must also guard that count against concurrent access using synchronisation primitives. Beyond the mechanics, the problem rewards careful handling of move vs. copy semantics, proper cleanup in destructors and reset operations, and correct operator overloading for dereferencing and member access.

  • Reference counting and lifetime semantics
  • Move and copy constructors and assignment operators
  • Mutex-based synchronisation for shared state
  • Memory safety and leak prevention
  • Operator overloading for smart-pointer idioms

Firms that ask questions like this

CTC, IMC, Optiver, Cit Sec, Aquatic, QRT, SIG, CMEGroup, Scalp Trade.