Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @java_coffee_cup,validated by @TBali,@selenae and @Ayza.
If you have any issues, feel free to ping them.
Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @java_coffee_cup,validated by @TBali,@selenae and @Ayza.
If you have any issues, feel free to ping them.
Hi,
While it is mentionned :
âWhen a student comes and wants to join the queue, he will search the queue from head to tail to check if any of his friends are already in the queueâ
It looks like the tests and validators expect this :
âWhen a student comes and wants to join the queue, he will search the queue from tail to head to check if any of his friends are already in the queueâ
(swap the words âheadâ and âtailâ)
Am I wrong ?
Nice puzzle anywayâŚ
Can you give an example?
I proposed the phrase before (the one actually present but is not what the tests and validators check) and the replacement phrase, which is how the game actually behaves.
Iâm not sure I understand your question.
Perhaps we misuderstand the words âheadâ and âtailâ for a queue. To me âheadâ represents the student that is the closest from the food counter, i.e. the one that will next be served, while the tail is the last who came into the queue.
Thatâs the correct interpretation, but can you give an example of why you think the tests and validators expect the search is from tail to head? For example, can you simulate one of the cases step by step to illustrate your point?
When a new student arrives, if you look at the queue from the head to the tail in order to find another student that belongs to the same group, some tests will fail.
If you look at the queue from the tail to the head, all tests and validators are OK ; thatâs why I suggest the correction above.
While reviewing other users code after finishing the puzzle, I noted that one of them had noted this point as a comment in his code.
Do you want me to send you my code (and how) so that you can verify this point by yourself ?
I donât understand how. Can you explain your point with reference to Test 1?
Input
2 14
111 112 113
221 222 223
111 222 333 112 223 113 221 -1 -1 -1 -1 -1 -1 -1
Output
111
112
113
222
223
221
333
Letâs say 333 was first in line, then a friend from his friend group (say 222 from the friend group 111 222 333) entered the queue, heâd be inserted right before 333 as expected.
However, when 111, the final one, enters the queue, then if the search was truly head-to-tail, heâd be inserted right behind 333 too, but contrary to that, heâs inserted behind 222, because itâs a tail-to-head search, a more âfirst to enter has the higher priority to skippingâ approach.
Itâs a good catch, I think the statement should be edited.
I think @ChristopheLa and @Ayza you both misunderstood the statement. The search is head to tail.
However, the sentence âIf any friend is found, he will jump the queue to insert himself right behind his friend group in the queueâ means: If you find a first friend (searching from head to tail), you still need to check if this friend is alone or there are multiple friends from the same friend group who are waiting in the queue together. You are inserted AFTER the last member of this friend group. (The first such group you found starting from the head.)
Right, I forgot about that part. Indeed, they get inserted right behind their current friend group in the queue.
I think I get it : Since no group can be split, you always get the same result if you :
Thanks for the comments.