Manafall Daily Quest

Subarray Sum Equals K

Function Name: subarraySum

Description

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

You may assume that the array and the target integer k will have at least one element.

Note that the array can contain both positive and negative integers.

Requirements

  • The function must have two parameters: an array of integers (nums) and a single integer (k).
  • The function should return the count of the subarrays as an integer.
  • Optimize the function for time complexity.
  • Do not use any built-in libraries or functions that would trivialize the problem (like combinations generator).
  • Subarrays are contiguous elements of the array.
  • A subarray with zero length (empty) is not a valid subarray.

Examples

Given nums = [1, 1, 1] and k = 2, your function should return 2, since the subarrays [1, 1] and [1, 1] sum to 2.Example call: subarraySum([1, 1, 1], 2) returns 2.

Matrix Spiral Copy

Thu Oct 31 2024

Write a function that takes a 2D array (matrix) of m x n elements and returns a list of its elements sorted in a spiral order.The spiral order starts at the top-left corner of the matrix and proceeds in a clockwise direction.The function should move towards the right on the top row, then proceed downwards along the last column, then move leftward along the bottom row, and finally move up the first column, then continue inwards, following the same pattern until all elements have been visited.

Prev Quest

Customized Caesar Cipher

Sat Nov 02 2024

The goal of this challenge is to implement a customized version of the Caesar Cipher, a classic encryption technique. The function should take a string and an integer as parameters, and return a new string where each letter is shifted by the specified number of places down the alphabet. Additionally, this customized cipher should leave non-letter characters unchanged and should maintain the casing of the characters.Your task is to write the function `caesarCipherEncrypt(text, shift)` where `text` is the string to be encrypted and `shift` is the number of places each letter must be shifted. The shift can be a positive or negative integer, meaning the letters can be shifted to the right or left respectively. Implement the function to wrap around, such that shifting 'z' by 1 would result in 'a', and shifting 'a' by -1 would result in 'z'.

Next Quest