Manafall Daily Quest

Balanced Subarrays

Function Name: findBalancedSubarrays

Description

The goal of this challenge is to write a function named 'findBalancedSubarrays' that takes in an array of integers and returns the total number of contiguous subarrays where the sum of elements on the left is equal to the sum of elements on the right.

A subarray consists of one or more consecutive elements of the array. For subarrays with an odd number of elements, the middle element should be considered as belonging to neither side.

Requirements

  • The function must handle arrays containing both positive and negative integers.
  • The function should return an integer representing the total count of balanced subarrays.
  • Time and space complexity analysis of the solution is required.
  • An empty array should be considered to have 0 balanced subarrays.
  • The array will contain at least 1 and no more than 1000 elements.
  • The function should not mutate the input array.

Examples

If the input is [1, 2, 3, 2, 1], the function should return 1 because there is only one balanced subarray: the whole array itself.If the input is [1, 0, 1, 0, 1, 0, 1], the function should return 4 as the balanced subarrays are: [1, 0, 1], [0, 1, 0], [1, 0, 1] and the entirety of the input array.

Links

https://en.wikipedia.org/wiki/Subarrayhttps://www.geeksforgeeks.org/subarray-substring-vs-subsequence-and-programs-to-generate-them/

Merge Time Intervals

Tue Aug 06 2024

Write a function 'mergeIntervals' that takes a list of time intervals, where each interval is represented as a pair of integers (start, end), and merges overlapping intervals.The intervals must be returned in ascending order and without overlaps.If an interval is contained within another, they should be merged into a single interval.The function should handle an arbitrary number of intervals

Prev Quest

Circular Queue Implementation

Thu Aug 08 2024

Implement a Circular Queue data structure with a fixed size using only primitive data structures (arrays, not language-specific collections). The CircularQueue class should support the following operations: enqueue, dequeue, peek, and isEmpty.The enqueue operation adds an item to the back of the queue, the dequeue operation removes an item from the front of the queue, peek returns the front element without removing it, and isEmpty indicates whether the queue is empty.If the queue is full and an enqueue operation is attempted, the function should return false or indicate that the queue is full. When dequeue is called on an empty queue, it should return null or an appropriate indicator of emptiness.

Next Quest