Merge Intervals
Function Name: mergeIntervals
Description
Write a function that merges overlapping intervals. The function should take an array of intervals, where each interval is represented as an array of two integers, and merge all overlapping intervals. The input array of intervals is not necessarily ordered in any way. The function should return an array of the merged intervals sorted in ascending order by the start of the intervals.
Requirements
- The function should handle merging multiple overlapping intervals.
- If two intervals overlap, they should be merged into a single interval that spans from the start of the first interval to the end of the second.
- The function should return a new array without modifying the input array.
- Intervals that do not overlap should remain as they are in the final merged array.
- The function should work for edge cases, such as an empty array input or an array with single interval.
Examples
Calling mergeIntervals([[1, 3], [8, 10], [2, 6], [15, 18]]) should return [[1, 6], [8, 10], [15, 18]].Calling mergeIntervals([[1, 4], [4, 5]]) should return [[1, 5]].Calling mergeIntervals([]) should return [].Calling mergeIntervals([[5, 7]]) should return [[5, 7]].
Links
Matrix Spiral Copy
Mon Sep 02 2024
Write a function that takes a 2D array (matrix) as input and returns a list of its elements in a spiral order. Start at the top-left corner of the input 2D array, go right and traverse the boundaries of the matrix in a clockwise spiral order, collecting elements until every element has been visited.
Raindrop Resonance
Wed Sep 04 2024
In this challenge, the task is to create a function that simulates the sound pattern produced by raindrops. The function will take an array representing different frequencies of raindrops and return a string representing the combined sound pattern.Each frequency will be an integer, and for each frequency 'n', the pattern will consist of a 'pling' every 'n' characters, with periods filling the spaces in between. The output should overlay these patterns on top of each other, starting with a capital 'P' for the first 'pling' and using lowercase 'p' for the subsequent ones.The function should handle combining the patterns where multiple 'plings' may coincide. In the case of coinciding 'plings', a single 'P' takes precedence over any number of lowercase 'p's, and multiple 'p's are represented by a single lowercase 'p'.The returned pattern string should only be as long as necessary to complete one full cycle of all input frequencies.