Data Structures: Create a Circular Queue : last test fail

Tell us what’s happening:


" Trying to dequeue past the write pointer should return null and does not advance the write pointer."

My log information tell me otherwise. Write is not modified by dequeue, read is not modified when returning null. is there something i am missing ? can i have the condition the test case check again ?

Your code so far

class CircularQueue {
constructor(size) {

 this.queue = new Array(size).fill(null); = 0;
 this.write = 0;
 this.max = size - 1;

 console.log(`myqueue:${size} r:${} w:${this.write} q:${this.queue}`)


print() {
  return this.queue;

enqueue(item) {
 // Only change code below this line
 if(this.queue[this.write] === null){
   this.queue[this.write] = item;
   this.write = (this.write+1)%(this.max+1);
 console.log(`enqueue:${item} r:${} w:${this.write} q:${this.queue}`)

 // Only change code above this line

dequeue() {
 // Only change code below this line
 let res = this.queue[];
 if (res != null) {
   this.queue[] = null; = (;
 console.log(`dequeue:${res} r:${} w:${this.write} q:${this.queue}`)
 return res;
 // Only change code above this line

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36.

Challenge: Create a Circular Queue

Link to the challenge:

My log against the most complete test look like this :

myqueue:3 r:0 w:0 q:,
enqueue:17 r:0 w:1 q:17,
enqueue:32 r:0 w:2 q:17,32,
enqueue:591 r:0 w:0 q:17,32,591
dequeue:17 r:1 w:0 q:,32,591
dequeue:32 r:2 w:0 q:,591
dequeue:591 r:0 w:0 q:,
dequeue:null r:0 w:0 q:,
dequeue:null r:0 w:0 q:,
dequeue:null r:0 w:0 q:,
dequeue:null r:0 w:0 q:,
enqueue:100 r:0 w:1 q:100,

@dste The problem is that your enqueue method does not meet the requirements in the instructions.

In addition, the enqueue method should return the item you enqueued if it is successful; otherwise it will return null .

thanks a lot, I totally misread this one.

I just found the github repo :

can i fork / pull request to add a test about this requirement ?

You want to add an extra test that just validates the enqueue method returns either the item or null? If so, I think that would be a good idea. I actually suggest creating two separate tests. One when it should return the item successfully enqueued and one when it should return null for unsuccessful enqueue.

To contribute, I suggest reading the following two documents:

1 Like