Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the end of the queue.
DSA Typescript
queue.[1](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop or dequeue to add elements
Using push which is for stacks, not queues
✗ Incorrect
In a queue, enqueue adds an element to the end.
2fill in blank
mediumComplete the code to remove the first element from the queue.
DSA Typescript
const first = queue.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using enqueue or push to remove elements
Using peek which only views the first element
✗ Incorrect
dequeue removes and returns the first element in the queue.
3fill in blank
hardFix the error in the code to check if the queue is empty.
DSA Typescript
if (queue.[1] === 0) { console.log('Empty'); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using size or count which are not valid properties
Using empty which is a method, not a property
✗ Incorrect
The length property gives the number of elements in an array-based queue.
4fill in blank
hardFill both blanks to create a queue and add an element to it.
DSA Typescript
const queue = new Array[1](); queue.[2](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using when numbers are added
Using enqueue which is not an array method
✗ Incorrect
We create a number array with new Array<number>() and add elements using push.
5fill in blank
hardFill all three blanks to create a queue, add two elements, and remove one.
DSA Typescript
const queue = new Array[1](); queue.[2](1); queue.[3](2); const first = queue.shift();
Attempts:
3 left
💡 Hint
Common Mistakes
Using instead of
Using enqueue which is not an array method
✗ Incorrect
Create a number array, add elements with push, and remove the first with shift.
