# remove the front of the queue and add it to the end queue.rotate(-1)
The example for this is far more convoluted than it needs to be and relies on a reader having previous knowledge of functions associated with the queue data structure. The comments are also very sparse. If a subject is being taught, then comments should be far more thorough, even excessive.
I am confused with this statement in Queue definition “That is, an item can be inserted and removed from the queue, but an item can only be removed from the queue after all the items added before it are removed first.” as same is mentioned in Stack definition.
In Queue we don’t have to remove the items which are added later. Please correct me if I am wrong.
Queue is first-in, first-out (FIFO), therefore for any item X added after adding an item Y, X can only be removed if Y has already been removed.
On Line 19, it shouldn’t be called pop right? since you’re using shift.
Shift() method removes the first element and whereas the pop() method removes the last element from an array.
Why is the splitWords function here? Another question, why is there substring used in the other solutions
This is under the topic queue where you can only remove the first item from the array. If you’re removing the last element it will be a stack. Both will yield similar result, you either remove first and add to back or you remove the last and insert to front
It’s the way the test cases are written here. The input is a string of “1 2 0 3” which translates into [‘1’, ‘2’, ‘0’, ‘3’]
my solution without using desque
def rotate_left_till_zero(nums): while nums!=0: nums = nums[1:]+ [nums] return nums
Why terms push and pop being used for Queue. Those are reserved for stack. For Queue, it is add() and remove()
For the JS solution, there’s little reason for the assignment
const queue = nums;
One can assume that the goal is a pure function - but this assignment won’t do that since JS arrays are passed by reference.
A useful assignment would be:
const queue = […nums];
const queue = nums.slice(); // Returns new array AND “queues” the reader to notice that it’s an array