Merge Intervals
Function Name: mergeIntervals
Description
Write a function called mergeIntervals that takes an array of intervals where each interval is a pair of integers indicating the start and end of a time block. The input array may not be sorted and could have overlapping intervals. The function should merge overlapping intervals and should return an array of the non-overlapping intervals that cover all the intervals in the input.
An interval is considered to be overlapping if it shares any common time with another interval. The start and end times are inclusive.
The intervals should be returned in sorted order by their start times.
Requirements
- The function should have a single parameter that accepts an array of intervals.
- If the input contains intervals that overlap, these should be merged into a single interval.
- The function should return a sorted array of intervals with no overlaps.
- The input can contain 0 or more intervals.
- Each interval will be represented as a pair, e.g. [start, end].
- Start time will always be less than or equal to end time for any interval.
Examples
Given input: [[1,4], [2,6], [8,10], [15,18]]Your function should return: [[1,6], [8,10], [15,18]]Explanation: Since the intervals [1,4] and [2,6] overlap, they are merged into [1,6].
Matrix Spiral Traversal
Mon Nov 11 2024
Write a function that takes a two-dimensional array (matrix) of MxN elements and returns an array of all elements in spiral order.The function should start at the top-left corner and proceed in a spiral pattern until every element has been visited, moving in the order of right, down, left, and up sides of the matrix's boundary.Consider that the input matrix can be of any size, but it is guaranteed to be non-empty.
Frequency Counter
Wed Nov 13 2024
Write a function named calculateFrequency that takes a string as its parameter. The function should return a dictionary or an object that maps each character in the string to the number of times it appears in the string. The frequency count should be case-sensitive, meaning that 'a' and 'A' should be counted as two different characters. Non-alphabetic characters should be included in the count as well. The output should be sorted by the character in ascending order.