Manafall Daily Quest

Merge Intervals

Function Name: mergeIntervals

Description

Write a function 'mergeIntervals' that given a list of intervals, merges all the overlapping intervals to produce a list that has only mutually exclusive intervals. The intervals are represented as pairs of integers.

Each interval is provided as an array with two integers indicating the start and end. The end of each interval is always greater than or equal to the start.

The function should return the merged intervals in ascending order starting with the interval with the lowest starting point.

Requirements

  • The function should accept a 2D array where each sub-array represents an interval.
  • The function should merge all overlapping intervals into one encompassing interval.
  • The function should not assume that the input intervals are already sorted.
  • The output should be sorted based on the start of each interval.
  • If an interval is contained within another, they should be merged into a single interval.
  • The function should handle empty lists of intervals and return an empty list in such cases.

Examples

Example 1: mergeIntervals([[1,3], [8,10], [2,6], [15,18]]) should return [[1,6], [8,10], [15,18]]Example 2: mergeIntervals([[1,4], [4,5]]) should return [[1,5]]Example 3: mergeIntervals([]) should return []

Links

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

String Permutations

Wed Sep 25 2024

In this challenge, you are required to write a function named 'generateStringPermutations' that takes a single string as an input parameter and returns all possible permutations of the characters in the string. A permutation is a re-arrangement of the elements of an ordered list. Each permutation should be unique, meaning if the string contains duplicate characters, permutations that are identical should be returned only once. The order of permutations in the returned collection does not matter.

Prev Quest

Pathfinding on a Grid

Fri Sep 27 2024

Write a function that takes a grid of walkable and non-walkable cells, as well as a start and an end position. The grid will be represented as a 2D array where 0s are walkable spaces and 1s are barriers. The start and end positions will be given as tuples (row, column). Your function should compute the shortest path from start to end and return the path as a list of tuples, detailing each step taken. If there is no path, return an empty list.

Next Quest