Skip to main content
All Questions

Implement a token ring with RingManager and RingElement classes.

Unlock detailed company stats for this questionUpgrade

Implement a ring of elements where only one element holds the "token" at any time. The first created element starts with the token. Calling release() passes the token to the next element in the ring. The ring is circular: releasing from the last element returns the token to the first.

Example asserts that had to pass: RingManager ringtest; RingElement piece1 = ringtest.create(); assert(piece1.hasToken()); // first element gets token RingElement piece2 = ringtest.create(); assert(piece1.hasToken()); // still with piece1 piece2.release(); assert(!piece1.hasToken()); assert(piece2.hasToken()); // token moved to piece2 piece2.release(); // token goes back to piece1 (circular)

C++ template given in the interview: #include <vector> #include <memory> class RingManager; class RingElement { private: public: bool hasToken(...) const; void release(...); }; class RingManager { private: public: RingManager(){} RingElement create(); bool hasToken(...); void release(...); };

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.