Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Ahh, you mean every person swaps with the person who has the same index from the other side of the queue (with respect to the 1's and 3's). that's not really clear at first, I thought we would swap everyone with the last person in the line.
In the instructions, it states that only known guests and members (1 and 2 respectively) can "cut" in front of the others, meaning they get sorted to the front, while everybody else has to maintain their position in line. In
[1,1,3,2,0]
, all the1
's and2
's get moved to the front (the two just gets moved in front of the 3), while everything else maintained their position in line (0
remained at the end since it isn't sorted).How to understand where 0 should stand after sort? In the first example:
"queue = [1, 1, 3, 2, 0] # The given queue
sorted = [1, 1, 2, 3, 0] # Sorted by priority" zero is taking the last place.
But in the second one it
s standing right after all two
s:"queue = [0, 8, 2, 1, 4, 2, 12, 3, 2] # The given queue
sorted = [1, 2, 2, 2, 0, 8, 4, 12, 3] # Sorted by priority"
This one is from discussion:
[1, 1, 1, 2, 2, 3, 4, 5, 0, 8, 5, 6]
Where to put zero and where should be decoys in sorted queue?
You have to create the algorithm to swap it. You sort it so that it has the proper order for you to be able to swap correctly. Re-read the scenario and take a look at the step-by-step examples underneath.
I don't understand why do we swap even after the queue had been sorted, and what is the algorithm that we use to swap after sorted?
Well, I've been able to get the index of the digit we want in the corresponding element, like if (
n
) is 9.then I know that its index is 3 in the 4th element, and the number of digits of the element is 4.
Am I going the right way? (C++)
Yeah, you're correct. After adding new line after each test case, it really isn't.
Probably you're printing the input of more than one test and confusing that with a single test input.
Didn't he say "All numbers are equal except for one"? then why there are some test cases that has multiple values?