Bloomberg L.P. Interview Question
802 Interview Reviews |
Back to all Bloomberg L.P. Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Financial Software Developer Intern at Bloomberg L.P.:
N people seated around a round table. Kth person removed every turn, until only one remains. Code the solution
See more for this Bloomberg L.P. Financial Software Developer Intern Interview
Helpful Question?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
by Anonymous:
using namespace std;
const int N = 10;
const int K = 3;
class Node {
public:
int num;
Node* next;
Node(int nnum) {num=nnum; next=NULL;}
};
int main()
{
//Defines circular linked list
Node* end = new Node(N);
Node* templast = end;
Node* temp;
for(int ii = N-1; ii>0; --ii)
{
temp = new Node(ii);
temp->next = templast;
templast = temp;
}
end->next = temp;
for(int ii = 0; ii<(K-2); ++ii) temp=temp->next; //Starts at K-1
//Executes Removal (Removes next node, then traverses K)
while(temp->num != (temp->next)->num)
{
temp->next=(temp->next)->next;
for(int ii = 0; ii<K; ++ii) temp=temp->next;
}
cout<<"Answer is: "<<temp->num<<endl;
return 0;
};