Do the solution in C/C++ with the Doubly Circular Linked List. Your codes should also be able to work for a million people.
There are N people numbered from 1 to N around a round table. Everyone has a different number in their hands between 1 and N. We start with the first person and count the number in his hand and ask the related person to leave the table. If the number in the card odd, we count clockwise. if it is even, we count counterclockwise. Ensure that all people leave the table. The first person to leave the table is the first person.
In the sample scenario, the first integer value in the table_in.txt file indicates the number of people around the table, it is 5. The value of the card in the first person’s hand is written on the next line, it is 3. The value of the second person’s card is written on the next line, it is 1.
In the table_out.txt file, print the order of people leaving the table.
Sample scenario:
table_in.txt
5
3
1
2
2
1
table_out.txt
1
4
2
3
5
Constraints
N < 1,000,000
Do the solution in C/C++ with the Doubly Circular Linked List. Your codes should also be able to work for a million people.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps