Manafall Daily Quest

Merge Intervals

Function Name: mergeIntervals

Description

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.

Requirements

  • The function should handle an empty list and return an empty list.
  • Intervals should be merged if they overlap or if one interval's start time is the same as the other's end time.
  • The returned intervals should be represented in the same way as the input (pairs of integers).
  • The function should not use any third-party libraries; only standard language features are allowed.
  • Assume all input intervals are valid with start times less than or equal to end times and are represented as an array of arrays.

Examples

Example 1:Input: mergeIntervals([[1,3],[2,6],[8,10],[15,18]])Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].Example 2:Input: mergeIntervals([[1,4],[4,5]])Output: [[1,5]]Explanation: Intervals [1,4] and [4,5] are considered overlapping.

Links

https://en.wikipedia.org/wiki/Interval_(mathematics)https://leetcode.com/problems/merge-intervals/

Circular Queue Implementation

Wed Dec 25 2024

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.

Prev Quest

Token Bucket Rate Limiter

Fri Dec 27 2024

Write a function 'rateLimiter' that simulates a token bucket rate limiter. The token bucket algorithm is used to control the amount of data that is transferred, which can help prevent denial of service attacks or network congestion. Your rate limiter must be stateful and should handle incrementing tokens in the bucket at a steady rate as well as decrementing them when a request is made.

Next Quest