Manafall Daily Quest

Two-Sum Problem

Function Name: findTwoSum

Description

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.

Requirements

  • The function must accept two parameters: an array of integers (nums) and a single integer (target).
  • If there are multiple pairs that add up to the target, the function can return any one of them.
  • The function should return null or an equivalent value if no pair is found.
  • Do not use any built-in two-sum functions, you may assume that each input would have exactly one solution, but you may not use the same element twice.
  • Optimize the function for a time complexity better than O(n^2) if possible.

Examples

Given nums = [2, 7, 11, 15] and target = 9, the function should return [0, 1] because nums[0] + nums[1] = 2 + 7 = 9.Given nums = [3, 2, 4] and target = 6, the function should return [1, 2].Given nums = [3, 3] and target = 6, the function should return [0, 1].Given nums = [1, 2, 3, 4] and target = 8, the function should return null as there are no two numbers that add up to 8.

Links

https://en.wikipedia.org/wiki/Subset_sum_problemhttps://leetcode.com/problems/two-sum/

Merge Intervals

Sun Nov 24 2024

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.

Prev Quest

Simple File Parser

Tue Nov 26 2024

In this challenge, you are required to write a function named `parseLogFile` that processes a simple log file. The log file is represented as a single string, with each entry separated by a newline character. Each entry in the log starts with a timestamp (in the format 'YYYY-MM-DD HH:MM:SS'), followed by a space, then a log level (either 'INFO', 'WARNING', or 'ERROR'), another space, and finally the log message. Your function should return the number of log messages for each log level.

Next Quest