Manafall Daily Quest

Merge Intervals

Function Name: mergeIntervals

Description

You are given an array of 'intervals' where intervals[i] = [starti, endi] represents the start and end of an exclusive time interval. Write a function to merge all overlapping intervals into a single one and return it in a way that minimizes the number of intervals. The function should return an array of the merged intervals sorted in ascending order by the start time.

Two intervals [a, b] and [c, d] overlap if b > c, assuming a < b and c < d. The merge should result in a new interval [a, d] if a < c and b > c (or vice versa).

Your function should be able to handle an arbitrary number of intervals and should consider edge cases where intervals are contained within one another or when there are no overlapping intervals.

Requirements

  • The mergeIntervals function must accept an array of intervals as its sole argument.
  • The function should not assume that the input intervals are in order. However, the output must be sorted.
  • The function must handle the merging of intervals properly, even if intervals have the same start or end times.
  • The function should handle an empty intervals array and return an empty array as a result.
  • Optimize the function for time and space complexity.

Examples

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] overlap, merge them into [1,6].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://www.geeksforgeeks.org/merging-intervals/

Elevator Simulation

Sat Nov 23 2024

Write a function that simulates the basic operation of an elevator dispatch system. The function's goal is to determine which elevator should be sent to a requested floor based on the current status of each elevator and a series of pick-up requests.Each elevator's status and the pick-up requests are defined by two parameters: a list of elevator objects with their current floor and direction of movement ('up', 'down', or 'idle'), and a list of pick-up requests as pairs (tuples) of integers representing the requested floor and desired direction ('1' for up and '-1' for down).The function must select the most appropriate elevator for each request based on proximity and direction. If multiple elevators are equally suitable, prioritize the one with the lower index in the elevator list.

Prev Quest

Two-Sum Problem

Mon Nov 25 2024

Write a function that takes an array of integers and a target integer as its parameters. The function should find two distinct elements in the array that sum up to the given target. The function should return indices of the two numbers such that they add up to the target, where the index of the first number is less than the index of the second number. If no such numbers exist, the function should return null or an equivalent value in your chosen language.

Next Quest