Manafall Daily Quest

Circular Queue Implementation

Function Name: CircularQueue

Description

In this challenge, you are required to implement a Circular Queue, a linear data structure that follows the First In First Out principle with a fixed size. The Circular Queue should wrap around to the beginning when the queue reaches its end. The implementation should support basic operations like enqueue (add an element), dequeue (remove an element), peek (get the element at the front of the queue), and an isEmpty method to check if the queue is empty.

Requirements

  • The CircularQueue class should have a constructor that takes an integer, indicating the size of the queue.
  • The enqueue method should add an item to the queue if there is space available, or return 'Queue is full' if the queue is at capacity.
  • The dequeue method should remove the item at the front of the queue and return it, or return 'Queue is empty' if there are no elements to remove.
  • The peek method should return the item at the front of the queue without removing it, or return 'Queue is empty' if the queue is empty.
  • The isEmpty method should return true if the queue is empty, false otherwise.
  • You must not use built-in queue or linked list data structures.
  • It is recommended to use a fixed-size array to store elements.

Examples

let circularQueue = new CircularQueue(3);circularQueue.enqueue(1); // returns nothingcircularQueue.enqueue(2); // returns nothingcircularQueue.enqueue(3); // returns 'Queue is full' since the queue size is 3circularQueue.peek(); // returns 1circularQueue.dequeue(); // returns 1circularQueue.isEmpty(); // returns false

Links

https://en.wikipedia.org/wiki/Circular_buffer

Custom String Compression

Tue Dec 24 2024

Write a function that performs a basic string compression using the counts of consecutive repeated characters.For example, the string 'aabcccccaaa' would become 'a2b1c5a3'.If the compressed string is not smaller than the original string, your function should return the original string.The function should handle uppercase and lowercase letters separately, meaning 'Aa' should be compressed as 'A1a1'.

Prev Quest

Merge Intervals

Thu Dec 26 2024

Write a function named 'mergeIntervals' that takes a list of intervals and merges all overlapping intervals.Each interval is represented as a pair of integers, where the first integer is the start time and the second is the end time.The function should return a list of merged intervals sorted by the start times.An interval [a,b] is considered to overlap with [c,d] if b >= c.

Next Quest