Top 40 Array Problems for Cocubes and Technical Interviews
1. Two Sum
Given an array of integers and a target sum, find two numbers that add up to the target.
Solution: Solution to be added.
2. Remove Duplicates from Sorted Array
Remove duplicates in-place from a sorted array.
Solution: Solution to be added.
3. Rotate Array
Rotate the array by a given number of steps.
Solution: Solution to be added.
4. Move Zeroes
Move all zeros in an array to the end while maintaining relative order of non-zero elements.
Solution: Solution to be added.
5. Remove Element
Remove all occurrences of a specific element in the array.
Solution: Solution to be added.
6. Binary Search
Implement binary search to find a target in a sorted array.
Solution: Solution to be added.
7. Find Minimum in Rotated Sorted Array
Find the minimum element in a rotated sorted array.
Solution: Solution to be added.
8. Search in Rotated Sorted Array
Search for a target in a rotated sorted array.
Solution: Solution to be added.
9. Kth Largest Element in an Array
Find the k-th largest element in an unsorted array.
Solution: Solution to be added.
10. Find Peak Element
Find a peak element in the array where arr[i] > arr[i-1] and arr[i] > arr[i+1].
Solution: Solution to be added.
11. Maximum Subarray Sum (Kadane’s Algorithm)
Find the maximum sum of a contiguous subarray.
Solution: Solution to be added.
12. Subarray Sum Equals K
Find the number of subarrays with a sum equal to k.
Solution: Solution to be added.
13. Longest Subarray with Sum Divisible by K
Find the longest subarray with a sum divisible by k.
Solution: Solution to be added.
14. Product of Array Except Self
Find the product of all elements except the one at the current index.
Solution: Solution to be added.
15. Sum of Subarray Minimums
Find the sum of minimum values in all subarrays.
Solution: Solution to be added.
16. Maximum Sum Subarray of Size K
Find the maximum sum of any subarray of size k.
Solution: Solution to be added.
17. Longest Substring with K Distinct Characters
Using two pointers, find the longest substring with exactly k distinct characters.
Solution: Solution to be added.
18. Find All Pairs with a Given Sum
Using the two-pointer approach, find all pairs that sum to a specific value.
Solution: Solution to be added.
19. Container With Most Water
Maximize the amount of water that can be contained between two lines in an array.
Solution: Solution to be added.
20. 3Sum
Find all unique triplets that add up to zero.
Solution: Solution to be added.
21. Trapping Rain Water
Calculate how much water can be trapped between the bars after raining.
Solution: Solution to be added.
22. Maximum Product Subarray
Find the maximum product of a contiguous subarray.
Solution: Solution to be added.
23. Find Duplicate Number
Find the duplicate in an array of integers where each integer appears once except one.
Solution: Solution to be added.
24. Merge Intervals
Merge all overlapping intervals into a single interval.
Solution: Solution to be added.
25. Insert Interval
Insert a new interval into a list of non-overlapping intervals and merge if necessary.
Solution: Solution to be added.
26. Top K Frequent Elements
Find the k most frequent elements in an array.
Solution: Solution to be added.
27. Majority Element
Find the element that appears more than n/2 times in the array.
Solution: Solution to be added.
28. Find All Duplicates in an Array
Find all elements that appear more than once in the array.
Solution: Solution to be added.
29. Intersection of Two Arrays
Find common elements in two arrays.
Solution: Solution to be added.
30. Find the Missing Number
Find the missing number from a sequence of numbers from 1 to n.
Solution: Solution to be added.
31. Spiral Matrix
Print elements of a matrix in spiral order.
Solution: Solution to be added.
32. Rotate Image (Matrix)
Rotate a 2D matrix by 90 degrees clockwise.
Solution: Solution to be added.
33. Set Matrix Zeroes
Set entire row and column to zero if an element is zero.
Solution: Solution to be added.
34. Search a 2D Matrix
Search for a target element in a sorted 2D matrix.
Solution: Solution to be added.
35. Word Search
Determine if a given word exists in a grid.
Solution: Solution to be added.
36. Partition Array into Three Parts with Equal Sum
Partition an array into three parts with the same sum.
Solution: Solution to be added.
37. Dutch National Flag Problem
Sort an array of 0s, 1s, and 2s in linear time.
Solution: Solution to be added.
38. Split Array Largest Sum
Split the array into m parts to minimize the largest sum among these parts.
Solution: Solution to be added.
39. Minimum Swaps to Bring Elements Less Than K Together
Minimize swaps to bring all elements less than or equal to K together.
Solution: Solution to be added.
40. Wiggle Sort
Rearrange elements such that they alternate between highs and lows.
Solution: Solution to be added.