1.
Find the maximum and minimum element in an array
Input: [3, 5, 1, 8, 2] → Output: max = 8, min = 1
2. Find the kth largest/smallest element in an array
Input: [7, 10, 4, 3, 20, 15], k = 3 → Output: 7
3. Check if the array is sorted
Input: [1, 2, 3, 4, 5] → Output: true
4. Remove duplicates from a sorted array
Input: [1, 1, 2] → Output: [1, 2]
5. Move all zeros to the end of the array
Input: [0, 1, 0, 3, 12] → Output: [1, 3, 12, 0, 0]
6. Find the second largest element in an array
Input: [12, 35, 1, 10, 34, 1] → Output: 34
7. Left rotate the array by 1 position
Input: [1, 2, 3, 4, 5] → Output: [2, 3, 4, 5, 1]
8. Check if a subarray with sum 0 exists
Input: [4, 2, -3, 1, 6] → Output: true
Medium Level
9. Find the subarray with the given sum (Sliding Window)
Input: [1, 4, 20, 3, 10, 5], sum = 33 → Output: [20, 3, 10]
10. Kadane’s Algorithm – Maximum subarray sum
Input: [-2,1,-3,4,-1,2,1,-5,4] → Output: 6 (subarray: [4,-1,2,1])
11. Find the missing number in an array of 1 to n
Input: [1, 2, 4, 5, 6] → Output: 3
12. Union and Intersection of two arrays
Input: arr1 = [1, 2, 4], arr2 = [2, 4, 6] → Union: [1, 2, 4, 6], Intersection: [2, 4]
13. Find the duplicate number in an array
Input: [1, 3, 4, 2, 2] → Output: 2
14. Sort an array of 0s, 1s, and 2s (Dutch National Flag Problem)
Input: [0, 1, 2, 0, 1, 2] → Output: [0, 0, 1, 1, 2, 2]
15. Find all pairs with a given sum
Input: arr = [1, 5, 7, -1], sum = 6 → Output: (1, 5), (7, -1)
Hard Level
16. Maximum Product Subarray
Input: [2, 3, -2, 4] → Output: 6
17. Merge Intervals
Input: [[1,3],[2,6],[8,10],[15,18]] → Output: [[1,6],[8,10],[15,18]]
18. Trapping Rain Water
Input: [0,1,0,2,1,0,1,3,2,1,2,1] → Output: 6
19. Find the median of two sorted arrays
Input: nums1 = [1, 3], nums2 = [2] → Output: 2.0
20. Count Inversions in an array
Input: [2, 4, 1, 3, 5] → Output: 3 (inversions: (2,1), (4,1), (4,3))