Manafall Daily Quest

Subarray Sum Equals K

Function Name: subarraySum

Description

Write a function subarraySum that takes an array of integers and an integer value k as its parameters.

The function should return the number of continuous subarrays whose sum equals to k.

A subarray is a contiguous part of the array.

Requirements

  • The function should take two parameters: an array of integers (nums) and an integer (k).
  • The function should return an integer representing the number of subarrays that sum up to k.
  • The array may contain positive, negative, or zero values.
  • The function should be able to handle an empty array, in which case the return value should be 0 if k is not 0.
  • Time complexity should be efficient and should avoid the brute force solution that checks every possible subarray sum.

Examples

Example 1: subarraySum([1, 1, 1], 2) should return 2.Example 2: subarraySum([-1, -1, 1], 0) should return 1.Example 3: subarraySum([10, 2, -2, -20, 10], -10) should return 3.

Links

https://en.wikipedia.org/wiki/Subarrayhttps://www.geeksforgeeks.org/find-subarray-with-given-sum-in-array-of-integers/

Custom Stack Min-Element

Mon Aug 26 2024

Write a function that, when implemented, operates a stack data structure allowing push and pop operations, but also includes a function to retrieve the smallest element in the stack at any given time. The stack should only store integers.The getMinFromStack function should work in constant time and with O(1) memory, meaning you should not use any additional data structures to keep track of the minimum element.Push and pop operations should also work in constant time (O(1)). This will require designing the stack in such a way that it can keep track of the minimum element as elements are pushed and popped.

Prev Quest

Simple Time Conversion

Wed Aug 28 2024

Write a function that converts 12-hour time format to 24-hour time format.The function will take a string representing the time in 12-hour format as input, e.g., '02:15PM' or '11:45AM'.It should return a string representing the time in 24-hour format, e.g., '14:15' or '11:45'.The input string will always be a valid time with uppercase 'AM' or 'PM'.

Next Quest