Manafall Daily Quest

Subarray Sum Equals K

Function Name: subarraySum

Description

Write a function named 'subarraySum' that takes in an array of integers and an integer 'k', and returns the number of continuous subarrays whose sum equals to 'k'.

Requirements

  • The function must accept two parameters: an array of integers and an integer 'k'.
  • The function should return an integer representing the number of continuous subarrays that sum to 'k'.
  • Consider that the array may contain both positive and negative integers.
  • The function should have a time complexity better than O(n^2).
  • The solution should not use any external libraries or modules.

Examples

Given an array: [1, 2, 3] and k = 3, the function should return 2 since the subarrays [1, 2] and [3] sum to 3.Given an array: [1, 1, 1] and k = 2, the function should return 2 since there are two subarrays that sum to 2, which are [1, 1] at different positions.

Links

https://en.wikipedia.org/wiki/Subarray

Uncommon Words from Two Sentences

Sat Dec 14 2024

Write a function named `findUncommonWords` that takes two strings `sentence1` and `sentence2`, which represent sentences composed of lowercase English letters and spaces (the spaces separate the words in the sentence).The function should return a list of the words that are uncommon in both sentences. A word is uncommon if it appears exactly once in one of the sentences and does not appear in the other sentence.The final list of uncommon words should not be in any particular order.

Prev Quest

Balanced Brackets

Mon Dec 16 2024

Write a function `isBalanced` that takes a string containing only brackets `()[]{}` and checks if the string is balanced. A string is balanced if all brackets are correctly closed and nested. The function should return `true` if the input string is balanced, otherwise, it should return `false`.

Next Quest