2.
Circular Array Maximum Sum
To find the maximum sum of a subarray in a circular array, you can either:
1. Use Kadane’s Algorithm to find the maximum subarray sum in the non-circular array.
2. For circular cases, calculate `total_sum - min_subarray_sum`, where `min_subarray_sum`
is the minimum subarray sum. Take the maximum of the two values.
Example Input:
arr = [8, -4, 3, -5, 4]
Example Output:
12
Explanation: The subarray `[4, 8]` is selected by wrapping around.
4.Find Missing Numbers
Find missing numbers in an array where numbers should range from 1 to n. Use an in-place
marking method or a hash set to find numbers that are missing.
Example Input:
arr = [4, 3, 2, 7, 8, 2, 3, 1]
Example Output:
[5, 6]
6.Longest Subarray with Equal 0s and 1s
Convert 0s to -1s and find the longest subarray with a sum of 0 using a hashmap to store the
first occurrence of sums.
Example Input:
arr = [0, 1, 0, 1, 1, 1, 0, 0]
Example Output:
6
Explanation: The subarray `[0, 1, 0, 1, 1, 0]` has equal 0s and 1s.
8.Merge Overlapping Intervals
Sort intervals by their start times, then merge overlapping ones by checking if the current
interval’s start is less than or equal to the previous interval’s end.
Example Input:
intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]
Example Output:
[[1, 6], [8, 10], [15, 18]]