Manafall Daily Quest

Array Pair Sum

Function Name: findPairWithGivenSum

Description

Write a function that finds and returns a pair of numbers from a given array of integers that adds up to a given sum. If there are multiple pairs that match the given sum, the function should return the first pair found. If no such pair exists, return an indication that no such pair has been found, such as null or an empty list.

Requirements

  • The function should take two parameters: an array of integers and the target sum.
  • The function should return an array containing the first pair of integers that add up to the sum, or an empty array if no pair is found.
  • The input array may contain positive or negative integers.
  • Do not use any built-in array searching methods like 'filter' or 'find'.
  • Optimize the function for time complexity.

Examples

If the input array is [1, 2, 3, 4, 5] and the sum is 6, the function should return [1, 5] because 1 and 5 add up to 6.If the input array is [0, -1, 2, -3, 1] and the sum is -2, the function should return [0, -2] since they are the first pair that adds up to -2.If the input array is [1, 2, 4, 4] and the sum is 8, the function should return [4, 4].If there is no pair with the given sum, for example, an array [1, 2, 5] with a sum of 10, it should return [].

Cinema Seat Allocation

Fri Sep 06 2024

Imagine there is a small cinema with a single row of seats, numbered from 1 to 50. Due to social distancing guidelines, every group attending must leave at least two empty seats between other groups. Your task is to write a function that determines the maximum number of attendees the cinema can accommodate given a list of reserved seats.Your function should return the maximum number of additional attendees that can be accommodated without violating the distancing guidelines. Note that groups can have an arbitrary number of members, but the number of groups is not provided.

Prev Quest

Simple Time Conversion

Sun Sep 08 2024

Write a function that converts 12-hour time format to 24-hour format.The function should be able to distinguish between AM and PM to convert the time accurately.Ignore the possibility of invalid time inputs and focus on the conversion logic.The input time will be a string in the format 'hh:mm AM' or 'hh:mm PM'.The output should be a string in the format 'HH:mm', where 'HH' is the hour in 24-hour format.

Next Quest