Manafall Daily Quest

Frequency Counter

Function Name: calculateFrequency

Description

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.

Requirements

  • The function must be able to handle an input string of any length.
  • Characters should be counted in a case-sensitive manner.
  • The returned frequency dictionary or object must have its keys sorted in ascending order.
  • The function must handle special characters, digits, and spaces, not just alphabetic ones.

Examples

Given the string 'hello world!', calculateFrequency('hello world!') should return { ' ': 1, '!': 1, 'd': 1, 'e': 1, 'h': 1, 'l': 3, 'o': 2, 'r': 1, 'w': 1 }.If an empty string is passed, calculateFrequency('') should return an empty dictionary or object.

Links

https://en.wikipedia.org/wiki/Character_frequencyhttps://www.asciitable.com/

Merge Intervals

Tue Nov 12 2024

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.

Prev Quest

Find Peak Element

Thu Nov 14 2024

Given an array of integers nums, write a function 'findPeakElement' that returns the index of any peak element. A peak element is an element that is greater than its neighbors. For the purposes of this problem, consider that the 'nums' array has -Infinity as neighbors past its bounds, meaning that if the first or last element is greater than their single neighbor (inside the array), they could be considered peak elements as well.You must write an algorithm that runs in O(log n) time complexity.

Next Quest