Bloomberg Senior engineer phone screen(NYC)- Token ring implementation
Was expecting a standard algo question but was asked this OOD style problem in phone screen for Senior engineer. I couldn't understand it in the interview as the interviewer had did a very poor job of explaining it. And as expected failed the interview. Was able to figure it out later.
You are given two classes 'RingManager' and 'RingElement' .
You need to 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 Test Cases and asserts that needed 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)*
// This was the 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(...);
};`


