Subarray Sum Equals K
Function Name: subarraySum
Description
Write a function called subarraySum that finds the total number of continuous subarrays whose sum equals to an integer k.
The function should take an array of integers and the integer k as parameters.
Return the count of such subarrays.
Requirements
- Ensure the function works with both positive and negative numbers.
- Optimize the function to have a time complexity better than O(n^2).
- The function should handle large arrays efficiently.
- Do not use any built-in functions for directly calculating subarray sums, like those found in mathematical computation libraries.
- The input array is not sorted, and the function needs to handle arbitrary order of elements.
Examples
Example 1: subarraySum([1, 1, 1], 2) should return 2 because there are two subarrays with a sum of 2: [1, 1] (the first two elements) and [1, 1] (the last two elements).Example 2: subarraySum([1, 2, 3], 3) should return 2 because there are two subarrays with a sum of 3: [1, 2] (the first two elements) and [3] (the last element alone).
Links
Balanced Brackets
Sun Nov 17 2024
Write a function `isBracketBalanced` which checks whether a given string has balanced brackets.The function takes a single string parameter where each character is either a standard opening or closing bracket ('(', ')', '{', '}', '[' or ']').It should return `true` if the brackets in the string are balanced, meaning that each opening bracket has a corresponding closing bracket and the brackets are properly nested.Return `false` if the string is empty, contains any other characters, or the brackets are not balanced.
Anagram Checker
Tue Nov 19 2024
The function isAnagram should take two strings as parameters and determine if they are anagrams or not. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, 'listen' is an anagram of 'silent'. The comparison should be case insensitive and ignore all spaces.