Given an integer array, find the length of the longest contiguous subarray whose sum of elements is zero.
Input: An array of integers, e.g., [1, 2, -3, 3, -1, -2]
Output: An integer representing the length of the longest subarray with sum zero.
Constraints:
First, let us initialize a variable say sum = 0 which stores the sum of elements traversed so far and another variable says max = 0 which stores the length of the longest subarray with sum zero. Declare a HashMap which stores the prefix sum of every element as a key and its index as a value. Now traverse the array, and add the array element to our sum.
Given a binary tree, return the values of the nodes that are visible when the tree is viewed from the top. The top view includes only the nodes that are the first encountered at each horizontal distance from the root when viewed from above.
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Kadane’s Algorithm Approach:
We iterate through the given array using a single loop and maintain a variable sum to store the sum of the current subarray. At each step, we add the current element to sum. If sum becomes negative at any point, we reset it to 0, since a negative sum would decrease the sum of any subsequent subarray. During the iteration, we keep track of the maximum sum encountered so far and return it as the result.
Note: If the array contains all negative numbers, initialize maxSum with the first element to ensure correctness.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?