Manafall Daily Quest

CircularQueue

Function Name: circularQueue

Description

In this challenge, you are tasked with implementing a Circular Queue data structure. The circular queue is a linear data structure that follows the First In First Out (FIFO) principle but also connects the last position back to the first position to make a circle. It is ideal for scenarios where the queue needs to be reset after it reaches the end.

Your implementation should support the following operations: enqueue, which inserts an element at the rear of the queue; dequeue, which removes and returns the element from the front of the queue; peek, which returns the front-most element without removing it from the queue; and isEmpty, which checks whether the queue is empty.

Requirements

  • The circularQueue function should have a parameter size indicating the maximum number of elements the queue can hold.
  • The queue should handle integer data, and when full, it should not enqueue new elements until space is freed up by dequeue operations.
  • Enqueue operation should return a boolean indicating whether the operation was successful.
  • Dequeue operation should return null (or equivalent) if there are no elements to remove.
  • Peek operation should return null if the queue is empty.
  • Implement an isEmpty method that returns a boolean indicating whether the queue is empty.
  • You should not use built-in queue or deque data structures provided by the language's standard libraries.

Examples

// Create a circular queue of size 3let cq = circularQueue(3);// Fill the queue completelycq.enqueue(1); // returns truecq.enqueue(2); // returns truecq.enqueue(3); // returns true// Check if queue is fullcq.enqueue(4); // returns false// Get the current front elementcq.peek(); // returns 1// Remove an element from the queuecq.dequeue(); // returns 1cq.peek(); // returns 2// Check if the queue is emptycq.isEmpty(); // returns false

Frequency Counter

Sat Oct 05 2024

Write a function that takes a string as its only parameter. Your function should return a mapping of each unique character to its frequency in the string. The frequency is defined as the number of times a character appears in the string. The function should ignore casing, meaning that 'a' and 'A' are considered the same character, and spaces and punctuation should be ignored. Your solution should not use any third-party libraries and should optimize for readability and efficiency.

Prev Quest

Merge Intervals

Mon Oct 07 2024

Given a collection of intervals, each represented as a pair of integers, write a function 'mergeIntervals' that merges all overlapping intervals. The function should return an array of intervals where overlapping intervals are merged into single intervals that span from the smallest to the largest numbers included in any of the overlapping intervals.Intervals are represented as an array/pair of two integers, for example, [1, 3]. An interval [a, b] is considered to overlap with [c, d] if there's any number x such that a <= x <= b and c <= x <= d.The returned intervals should be in ascending order of their start values. Assume that the input list is unsorted.

Next Quest