0% found this document useful (0 votes)
252 views53 pages

Converted Text

Uploaded by

sahilraj0301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
252 views53 pages

Converted Text

Uploaded by

sahilraj0301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

#### 1. Basics of Arrays & Memory Layout (Approx.

300 Problems)

**Fundamental Declarations, Access & Properties:**


1. Initialize Fixed-Size Integer Array.
2. Initialize Fixed-Size Floating-Point Array.
3. Initialize Fixed-Size Boolean Array.
4. Access Element at Given Index.
5. Update Element Value at Specified Index.
6. Retrieve Array's Current Element Count.
7. Query Array's Allocated Memory Capacity.
8. Calculate Memory Usage for Integer Array (Bytes).
9. Find Smallest Value in Unordered Integer Array.
10. Find Largest Value in Unordered Integer Array.
11. Compute Sum of All Integer Array Elements.
12. Calculate Average of Numerical Array Elements.
13. Count Even Values in Integer Array.
14. Count Odd Values in Integer Array.
15. Verify if Array Contains No Elements.
16. Generate a Shallow Copy of an Array.
17. Generate a Deep Copy of a Simple-Type Array.
18. Print Array Elements from Last to First.
19. Swap First and Last Elements In-place.
20. Determine if Array is Non-Decreasing.
21. Determine if Array is Strictly Increasing.
22. Populate Array with Alternating 0s and 1s.
23. Populate Array with Sequential Integers.
24. Combine Two Integer Arrays into New Array.
25. Determine Frequency of a Target Value in Array.
26. Replace All Occurrences of Old Value with New Value.
27. Check if All Array Elements are Identical.
28. Check for Presence of a Target Element.
29. Circularly Left Shift Array by One Position.
30. Circularly Right Shift Array by One Position.
31. Interleave Elements from Two Equal-Length Arrays.
32. Remove First Occurrence of Value from Array.
33. Remove All Occurrences of Value from Array.
34. Find Smallest Positive Integer Missing from Array.
35. Find Smallest Non-Negative Integer Missing from Array.
36. Identify Unique Duplicate in 1 to N Range Array.
37. Determine if Any Duplicates Exist in Array.
38. Count Elements Greater Than a Threshold.
39. Count Elements Less Than a Threshold.
40. Calculate Range of Array Values (Max - Min).
41. Find Second Smallest Element in Array.
42. Find Second Largest Element in Array.
43. Reverse Subarray Between Two Given Indices.
44. Swap Adjacent Elements in Pairs.
45. Check if Array can be Sorted by Swapping Only Adjacent Elements.
46. Remove K Smallest Elements from Array.
47. Remove K Largest Elements from Array.
48. Find Kth Smallest Element (Unsorted).
49. Find Kth Largest Element (Unsorted).
50. Count Elements Smaller Than Current Element to Its Right (Brute Force).
51. Count Elements Greater Than Current Element to Its Right (Brute Force).
52. Maximize Difference Between Two Elements `A[j] - A[i]` where `j > i`.
53. Maximize Difference Between Any Two Elements `|A[j] - A[i]|`.
54. Minimize Difference Between Any Two Elements `|A[j] - A[i]|`.
55. Sort Array by Absolute Values.
56. Sort Array in Wave-like Pattern.
57. Segregate Positive and Negative Numbers (Positive First).
58. Partition Array around a Given Pivot Value.
59. Move All Zeroes to the Beginning of Array.
60. Move All Ones to the End of Array (Binary Array).
61. Find Missing K Smallest Positive Integers.
62. Find Missing K Largest Positive Integers (Within Range).
63. Compute XOR Sum of All Array Elements.
64. Compute Bitwise AND Sum of All Array Elements.
65. Compute Bitwise OR Sum of All Array Elements.
66. Find Minimum Absolute Difference Among All Pairs.
67. Count Elements with Frequency Exceeding N/K.
68. Sort Array by Number of Set Bits in Elements.
69. Find Kth Smallest Pair Difference.
70. Find Kth Largest Pair Difference.
71. Count Pairs with Difference Exactly K.
72. Count Pairs with Sum Exactly K.
73. Count Pairs with Sum Less Than K.
74. Count Pairs with Sum Greater Than K.
75. Find Maximum Value After K Operations (Specific Op).
76. Minimize Maximum Value After K Operations.
77. Maximize Minimum Value After K Operations.
78. Verify All Array Elements are Distinct.
79. Find First Non-Repeating Element.
80. Find Last Non-Repeating Element.
81. Generate All Cyclic Rotations of an Array.
82. Generate All Contiguous Subarrays (Storing as lists).
83. Generate All Subsequences (Storing as lists).
84. Count Pairs with Identical Values.
85. Count Triplets with Identical Values.
86. Group Elements by Their Frequency.
87. Group Elements by Their Parity.
88. Group Elements by Their Sign.
89. Find Minimum Length Unsorted Subarray to Sort Entire Array.
90. Check if Array is Monotonically Increasing.
91. Check if Array is Monotonically Decreasing.
92. Find Unique Element Appearing Once (Others Twice).
93. Find Unique Element Appearing Once (Others Thrice).
94. Find Two Unique Elements (Others Appear Twice).
95. Validate Array as a Permutation of 1 to N.
96. Convert Array to Zigzag Pattern.
97. Calculate Product of All Array Elements.
98. Find First Element Not Equal to Its Index.
99. Calculate Sum of All Odd-Length Subarrays.
100. Calculate Sum of All Even-Length Subarrays.
101. Find Max Sum Subarray with Only Positive Elements.
102. Find Max Sum Subarray with Only Negative Elements.
103. Count Subarrays Where Max Element is K.
104. Count Subarrays Where Min Element is K.
105. Find K Most Frequent Elements.
106. Find K Least Frequent Elements.
107. Count Elements Smaller Than Neighbors.
108. Count Elements Greater Than Neighbors.
109. Find Longest Subarray with Same Parity for Adjacent Elements.
110. Find Smallest Positive Integer Missing (Using Sign Flips).
111. Find First Missing Positive Integer (Using Hash Set).
112. Compute Bitwise XOR of All Subarrays (Brute Force).
113. Find Longest Subarray with Equal Number of Even and Odd Elements.
114. Find the Longest Subarray with Equal Number of Positive and Negative Elements.
115. Count Elements Whose Value is `X` and `2X` is also Present.
116. Count Elements Whose Value is `X` and `X/2` is also Present.
117. Check if All Elements are Distinct (Optimized).
118. Find Smallest Index of Duplicate Element.
119. Find Largest Index of Duplicate Element.
120. Convert Array to Alternating Sign Sequence.
121. Calculate Sum of Squares of Array Elements.
122. Find Max Sum of `A[i] + A[j]` where `i < j`.
123. Find Min Sum of `A[i] + A[j]` where `i < j`.
124. Find Max Product of `A[i] * A[j]` where `i < j`.
125. Find Min Product of `A[i] * A[j]` where `i < j`.
126. Count Triplets `(i, j, k)` with `A[i] < A[j] < A[k]`.
127. Count Triplets `(i, j, k)` with `A[i] > A[j] > A[k]`.
128. Find Longest Subarray of Consecutive Integers.
129. Find Shortest Subarray of Consecutive Integers.
130. Count Subarrays that are Palindromic (Viewed as String).
131. Count Distinct Subarrays.
132. Count Distinct Subsequences.
133. Find Longest Palindromic Substring (Brute Force).
134. Find Longest Palindromic Subsequence (Brute Force).
135. Find Elements that Appear Twice (Using In-place Mod).
136. Find Elements that Appear K Times.
137. Find Kth Smallest Element (Using Min-Heap/Max-Heap).
138. Find Kth Largest Element (Using Min-Heap/Max-Heap).
139. Determine if Target Sum can be Formed by Two Elements.
140. Determine if Target Sum can be Formed by Three Elements.
141. Count Inversions (Brute Force).
142. Find Equilibrium Point (Brute Force).
143. Find All Equilibrium Points.
144. Find Longest Monotonic Subarray.
145. Find Longest Alternating Subarray.
146. Count Subarrays with a Specific Max Element.
147. Count Subarrays with a Specific Min Element.
148. Find the Most Frequent Element (Handle Ties).
149. Find Smallest Missing Positive Integer (Cyclic Sort).
150. Find All Missing Positive Integers (Cyclic Sort).
151. Count Prime Numbers in Array.
152. Sum of Prime Numbers in Array.
153. Find All Indices Where `A[i] == i`.
154. Find First Index Where `A[i] == i`.
155. Find Last Index Where `A[i] == i`.
156. Remove Element from Array (Return New Array).
157. Remove All Duplicates (Return New Array).
158. Check if Array Contains a Pair with XOR Sum K.
159. Count Pairs with XOR Sum K.
160. Find Max XOR Pair.
161. Find Min XOR Pair.
162. Count Pairs with Bitwise AND Sum K.
163. Count Pairs with Bitwise OR Sum K.
164. Find Max Product of Three Numbers.
165. Find Min Product of Three Numbers.
166. Find Max Product of Two Numbers.
167. Find Min Product of Two Numbers.
168. Find the Single Odd Occurring Number.
169. Find the Single Even Occurring Number.
170. Check if a Subset Sums to K (Brute Force/Backtracking).
171. Count Subsets that Sum to K (Brute Force/Backtracking).
172. Maximize Sum of K Elements (No Repetition).
173. Maximize Sum of K Elements (With Repetition).
174. Minimize Sum of K Elements (No Repetition).
175. Minimize Sum of K Elements (With Repetition).
176. Generate Subsets of Size K.
177. Generate Subsets of Size K with Specific Sum.
178. Generate All Combinations.
179. Generate All Permutations.
180. Check if Array Represents a Valid Sequence (e.g., 1,2,3 or 3,2,1).
181. Find Longest Consecutive Sequence.
182. Count Pairs with Elements `A[i]` and `A[j]` such that `A[i]` is divisible by `A[j]`.
183. Count Pairs with Elements `A[i]` and `A[j]` such that `A[i]` is a factor of `A[j]`.
184. Count Pairs with Elements `A[i]` and `A[j]` sharing a common factor.
185. Count Pairs with Elements `A[i]` and `A[j]` that are coprime.
186. Find the Smallest Number of Rotations to Sort an Array.
187. Find the Largest Number of Rotations to Sort an Array.
188. Find the Maximum Difference Between Adjacent Elements.
189. Find the Minimum Difference Between Adjacent Elements.
190. Count Pairs `(i, j)` where `A[i] == A[j] + K`.
191. Count Pairs `(i, j)` where `A[i] == A[j] - K`.
192. Calculate Sum of `min(A[i], A[j])` for all pairs `i < j`.
193. Calculate Sum of `max(A[i], A[j])` for all pairs `i < j`.
194. Find Longest Subarray Where Adjacent Elements are Coprime.
195. Find Longest Subarray Where Adjacent Elements are Co-prime.
196. Find Longest Subarray Where Adjacent Elements have Same Parity.
197. Find Longest Subarray Where Adjacent Elements have Different Parity.
198. Count Subarrays Where Adjacent Elements have Same Parity.
199. Count Subarrays Where Adjacent Elements have Different Parity.
200. Find Most Frequent Element in Array (Smallest Index on Tie).
201. Find Most Frequent Element in Array (Largest Index on Tie).
202. Find Most Frequent Element in Array (Smallest Value on Tie).
203. Find Most Frequent Element in Array (Largest Value on Tie).
204. Find All Elements that are Local Maxima.
205. Find All Elements that are Local Minima.
206. Count Elements that are Local Maxima.
207. Count Elements that are Local Minima.
208. Check if Array Can Be Partitioned into K Equal Sum Subsets (Backtracking Intro).
209. Find All Partitions of Array into K Equal Sum Subsets (Backtracking Intro).
210. Find Max Sum of K Elements from Array (allowing to choose same element multiple times).
211. Find Min Sum of K Elements from Array (allowing to choose same element multiple times).
212. Count Subarrays whose elements are all distinct (Brute Force).
213. Find Longest Subarray whose elements are all distinct (Brute Force).
214. Count Subarrays whose elements are all even.
215. Count Subarrays whose elements are all odd.
216. Find Longest Subarray whose elements are all even.
217. Find Longest Subarray whose elements are all odd.
218. Find Maximize `A[i] + i` for any `i`.
219. Find Minimize `A[i] + i` for any `i`.
220. Find Maximize `A[i] - i` for any `i`.
221. Find Minimize `A[i] - i` for any `i`.
222. Find Maximize `A[i] * i` for any `i`.
223. Find Minimize `A[i] * i` for any `i`.
224. Find All Combinations of `K` Elements from an Array with Repetition.
225. Find All Permutations of an Array with Duplicates.
226. Count Pairs `(i, j)` where `A[i] < A[j]` and `i < j` (Brute Force).
227. Count Pairs `(i, j)` where `A[i] > A[j]` and `i < j` (Brute Force).
228. Check if Array can be made Monotonic with one Swap.
229. Check if Array can be made Monotonic with one Deletion.
230. Find Smallest Element in a Sorted and Rotated Array (No Duplicates).
231. Find Smallest Element in a Sorted and Rotated Array (With Duplicates).
232. Find Largest Element in a Sorted and Rotated Array (No Duplicates).
233. Find Largest Element in a Sorted and Rotated Array (With Duplicates).
234. Calculate Sum of Elements at Prime Indices.
235. Calculate Sum of Elements at Fibonacci Indices.
236. Remove First K Elements.
237. Remove Last K Elements.
238. Insert K Elements at Beginning.
239. Insert K Elements at End.
240. Insert K Elements at Middle.
241. Check if Array is Palindromic (Direct comparison).
242. Check if Array is Arithmetic Progression.
243. Check if Array is Geometric Progression.
244. Find Missing Number in Arithmetic Progression.
245. Find Missing Number in Geometric Progression.
246. Find Longest Arithmetic Progression Subarray.
247. Find Longest Geometric Progression Subarray.
248. Count Arithmetic Progression Subarrays.
249. Count Geometric Progression Subarrays.
250. Find the Kth Element in a Cyclically Sorted Array.
251. Find the Kth Element in a Sorted Array with Duplicates.
252. Find the Kth Element in a Sorted Array (no duplicates).
253. Find the Kth Element from End of Array.
254. Compute Hash Value of an Array.
255. Compute Custom Hash Value of Array.
256. Find First Occurrence of Value in Rotated Sorted Array.
257. Find Last Occurrence of Value in Rotated Sorted Array.
258. Determine if Array Contains Elements from 1 to N.
259. Determine if Array Contains All Unique Elements from 1 to N.
260. Find Max Sum of `A[i] + B[j]` for any `i, j`.
261. Find Min Sum of `A[i] + B[j]` for any `i, j`.
262. Find Max Product of `A[i] * B[j]` for any `i, j`.
263. Find Min Product of `A[i] * B[j]` for any `i, j`.
264. Find All Pairs `(i, j)` where `A[i] + A[j] == K`.
265. Find All Pairs `(i, j)` where `A[i] * A[j] == K`.
266. Find All Pairs `(i, j)` where `A[i] XOR A[j] == K`.
267. Count Numbers with Unique Digits in Array Elements.
268. Find Maximize `A[i]` such that `A[i] == A[j] + K` for some `j`.
269. Find Minimize `A[i]` such that `A[i] == A[j] + K` for some `j`.
270. Find Maximize `A[i]` such that `A[i] % K == 0`.
271. Find Minimize `A[i]` such that `A[i] % K == 0`.
272. Count Elements Divisible by K.
273. Count Elements Not Divisible by K.
274. Check if Array is a Subarray of Another Array.
275. Check if Array is a Subsequence of Another Array.
276. Find All Indices where `A[i]` is a Local Maximum or Minimum.
277. Find the Smallest Missing Non-Negative Integer in an Unsorted Array.
278. Find the Largest Missing Non-Negative Integer in an Unsorted Array (within bounds).
279. Compute the Median of an Unsorted Array.
280. Find the Maximum Product of Any `K` Elements.
281. Find the Minimum Product of Any `K` Elements.
282. Count Pairs where `A[i] = A[j] * 2`.
283. Count Pairs where `A[i] = A[j] / 2`.
284. Count Pairs where `A[i]` is a prime and `A[j]` is a composite.
285. Find Longest Subarray whose elements are all squares.
286. Count Subarrays whose elements are all squares.
287. Find the Sum of Elements at Even Indices.
288. Find the Sum of Elements at Odd Indices.
289. Find the Product of Elements at Even Indices.
290. Find the Product of Elements at Odd Indices.
291. Convert Array to Linked List.
292. Convert Linked List to Array.
293. Find All Elements that are Prime.
294. Find All Elements that are Composite.
295. Sum of Squares of Even Numbers.
296. Sum of Squares of Odd Numbers.
297. Find Maximize `A[i] + A[j] - (j-i)` where `i < j`.
298. Find Maximize `A[i] + A[j] + (j-i)` where `i < j`.
299. Find Minimize `A[i] + A[j] - (j-i)` where `i < j`.
300. Find Minimize `A[i] + A[j] + (j-i)` where `i < j`.

#### 2. Traversal & Basic Operations (Insert/Delete/Update) (Approx. 300 Problems)

**Traversal & Search:**


1. Perform Iterative Linear Scan for Target.
2. Perform Recursive Linear Scan for Target.
3. Execute Iterative Binary Search for Target in Sorted Array.
4. Execute Recursive Binary Search for Target in Sorted Array.
5. Find First Occurrence Index of Target in Sorted Array.
6. Find Last Occurrence Index of Target in Sorted Array.
7. Find Floor Value of Target in Sorted Array.
8. Find Ceiling Value of Target in Sorted Array.
9. Count Occurrences of Target in Sorted Array.
10. Determine if Target is Present in Sorted Rotated Array.
11. Determine if Target is Present in Sorted Rotated Array with Duplicates.
12. Find Minimum Element in Sorted Rotated Array.
13. Find Minimum Element in Sorted Rotated Array with Duplicates.
14. Find Maximum Element in Sorted Rotated Array.
15. Find Maximum Element in Sorted Rotated Array with Duplicates.
16. Search for Element in 2D Row-Sorted Matrix.
17. Search for Element in 2D Row/Column-Sorted Matrix.
18. Traverse and Print Array Elements.
19. Traverse and Print Array Elements in Reverse.
20. Traverse and Print Every Kth Element.
21. Traverse and Sum Elements at Even Indices.
22. Traverse and Sum Elements at Odd Indices.
23. Traverse and Count Prime Elements.
24. Traverse and Count Palindromic Elements (if elements are strings/numbers).
25. Traverse and Find First Even Number.
26. Traverse and Find Last Odd Number.
27. Traverse and Find Elements Greater Than Average.
28. Traverse and Find Elements Less Than Average.
29. Traverse and Apply Function to Each Element.
30. Traverse and Collect Elements Satisfying a Condition.

**Insertion Operations:**
31. Insert Element at Array's Tail (Dynamic Array).
32. Insert Element at Array's Head (Dynamic Array).
33. Insert Element at Specific Index (Dynamic Array).
34. Insert Element into Sorted Array (Maintain Sort Order).
35. Insert Multiple Elements at Specific Index.
36. Insert Element at First Empty Slot.
37. Insert Element if Not Already Present.
38. Insert Element and Remove Duplicates.
39. Insert Element to Maintain Monotonicity.
40. Insert Element into Circular Array.
41. Insert Element into 2D Matrix (Specific Cell).
42. Insert Row into 2D Matrix.
43. Insert Column into 2D Matrix.
44. Insert Element into a Gap in Sorted Array.
45. Insert K Elements into Array at Once.
46. Insert Element Such That Array Remains Balanced.
47. Insert Element to Avoid Specific Pattern.
48. Insert Element and Return its New Index.
49. Insert Element and Return New Array Size.
50. Insert Element Without Shifting (if possible, overwrite).

**Deletion Operations:**
51. Delete Element from Array's Tail (Dynamic Array).
52. Delete Element from Array's Head (Dynamic Array).
53. Delete Element at Specific Index (Dynamic Array).
54. Delete Element by Value (First Occurrence).
55. Delete All Occurrences of Specific Value.
56. Delete Element from Sorted Array (Maintain Sort).
57. Delete Elements within a Specific Range of Indices.
58. Delete Elements with Values within a Specific Range.
59. Delete Duplicate Elements (Keep First Occurrence).
60. Delete Duplicate Elements (Keep Last Occurrence).
61. Delete Duplicate Elements (Remove All).
62. Delete Elements to Maintain Monotonicity.
63. Delete Elements to Reduce Array Size to K.
64. Delete Elements from Circular Array.
65. Delete Row from 2D Matrix.
66. Delete Column from 2D Matrix.
67. Delete Elements Based on Parity (e.g., all even numbers).
68. Delete Elements Based on Prime/Composite Property.
69. Delete K Elements to Maximize Remaining Sum.
70. Delete K Elements to Minimize Remaining Sum.
71. Delete K Elements to Maximize Remaining Product.
72. Delete K Elements to Minimize Remaining Product.
73. Delete Elements and Return New Array.
74. Delete Elements and Return New Array Size.
75. Delete Elements and Return List of Deleted Elements.
76. Delete Elements and Re-index Remaining.
77. Delete Element by Value and Return True/False.
78. Delete Elements to Achieve a Target Average.
79. Delete Elements to Achieve a Target Sum.
80. Delete Elements to Avoid Specific Patterns.

**Update Operations:**
81. Update Element at Specific Index to New Value.
82. Update All Occurrences of Old Value to New Value.
83. Increment All Elements by a Constant.
84. Decrement All Elements by a Constant.
85. Multiply All Elements by a Constant.
86. Divide All Elements by a Constant.
87. Update Elements within a Range `[L, R]` to a New Value.
88. Increment Elements within a Range `[L, R]` by a Value.
89. Update Elements Based on a Condition (e.g., `A[i] = A[i]*2` if `A[i]` is even).
90. Update Elements to Their Squares.
91. Update Elements to Their Absolute Values.
92. Update Elements and Return Number of Changes.
93. Update Element in 2D Matrix.
94. Update All Elements in a Row.
95. Update All Elements in a Column.
96. Update Elements to Their Rank Order.
97. Update Elements to Achieve Specific Sum.
98. Update Elements to Achieve Specific Product.
99. Update Elements for Cyclic Shift.
100. Update Elements to Reverse Subarray.
101. Update Elements to Maximize Array Sum.
102. Update Elements to Minimize Array Sum.
103. Update Elements to Make Array Sorted.
104. Update Elements to Make Array Monotonic.
105. Update Elements to Remove Duplicates (by setting to dummy value).
106. Update Elements to Move Zeroes.
107. Update Elements to Move Specific Value to End.
108. Update Elements to Achieve Target Average.
109. Update Elements and Return Difference from Old Value.
110. Update Elements to Match Another Array.

**Combined & Advanced Operations:**


111. Move Zeroes to End (In-place, Preserve Order).
112. Remove Duplicates from Sorted Array (In-place, Unique).
113. Remove Duplicates from Sorted Array (In-place, Max Two Occurrences).
114. In-place Value Removal (Return New Length).
115. Rotate Array by K Positions (In-place).
116. Reverse Array In-place.
117. Sort Array of 0s, 1s, 2s In-place.
118. Merge Two Sorted Arrays into First Array (In-place).
119. Generate Squares of Sorted Array (In-place conversion if possible, or two pointers for new
array).
120. Find Missing Number (Using XOR).
121. Find Duplicate Number (Using Floyd's Cycle Detection).
122. Find All Duplicates (Using Cyclic Sort / In-place Hash).
123. Find Corrupt Pair (Missing and Duplicate) Using Cyclic Sort.
124. Find First Missing Positive Integer (Cyclic Sort).
125. Find Kth Smallest Element (Quickselect / Partition).
126. Find Kth Largest Element (Quickselect / Partition).
127. Find Next Lexicographical Permutation.
128. Implement Product of Array Except Self (O(1) extra space).
129. Decode XORed Array (Given First Element).
130. Shift Array Left by K Positions (In-place).
131. Shift Array Right by K Positions (In-place).
132. Interleave Two Arrays In-place.
133. Partition Array Around a Value (In-place).
134. Sort Array by Parity (Even First, In-place).
135. Sort Array by Parity (Alternating, In-place).
136. Segregate Positive and Negative Numbers (In-place, Maintain Order).
137. Segregate Positive and Negative Numbers (In-place, Any Order).
138. Replace Elements with Greatest Element on Right Side.
139. Replace Elements with Smallest Element on Right Side.
140. Count Elements Not in Their Sorted Positions.
141. Find Pivot Index (Using Two Pointers or Prefix Sums).
142. Check if Array is Sorted and Rotated.
143. Find First and Last Position of Element in Sorted Array (Binary Search based).
144. Find Insertion Point for Element in Sorted Array (Binary Search based).
145. Find Pair with Target Sum in Sorted Array (Two Pointers).
146. Find Triplets with Zero Sum (Two Pointers).
147. Find Triplets with Sum Closest to Target (Two Pointers).
148. Find Quadruplets with Target Sum (Two Pointers).
149. Maximize Water Container Area (Two Pointers).
150. Calculate Trapped Rainwater (Two Pointers).
151. Reverse Vowels in a String (Two Pointers).
152. Compare Backspaced Strings (Two Pointers).
153. Minimum Length String After Deleting Similar Ends (Two Pointers).
154. Count Pairs with Difference K (Two Pointers).
155. Count Pairs with Sum K (Two Pointers).
156. Count Pairs with Sum Less Than K (Two Pointers).
157. Count Pairs with Sum Greater Than K (Two Pointers).
158. Count Pairs with Sum K in Sorted Rotated Array.
159. Find Max Product of Three Numbers (Sorted Array).
160. Find Min Product of Three Numbers (Sorted Array).
161. Find Maximize `A[i] + A[j]` for `i < j` (One pass).
162. Find Minimize `A[i] + A[j]` for `i < j` (One pass).
163. Find Maximize `A[i] - A[j]` for `i < j` (One pass).
164. Find Minimize `A[i] - A[j]` for `i < j` (One pass).
165. Find Maximize `A[i] * A[j]` for `i < j` (One pass).
166. Find Minimize `A[i] * A[j]` for `i < j` (One pass).
167. Count Inversions (Merge Sort approach).
168. Find Longest Consecutive Sequence (Hash Set + Traversal).
169. Find Longest Subarray with Equal Number of 0s and 1s (Hash Map + Traversal).
170. Find Longest Subarray with Equal Number of 0s, 1s, and 2s (Hash Map + Traversal).
171. Find All Numbers Disappeared in an Array (In-place modification).
172. Find All Elements that Appear Twice (In-place modification).
173. Remove Duplicates (Keep `K` occurrences).
174. Shift All Negative Numbers to One Side.
175. Shift All Positive Numbers to One Side.
176. Reorder Array by Indices (Given Permutation).
177. Find First Element Greater Than Target.
178. Find Last Element Less Than Target.
179. Find Smallest Element Not Present in a Sorted Array with Range.
180. Find Largest Element Not Present in a Sorted Array with Range.
181. Remove Elements from a Dynamic Array to Shrink Capacity.
182. Insert Elements into a Dynamic Array to Grow Capacity.
183. Check if Array is Partitioned.
184. Partition Array to Place All Even Numbers Before Odd Numbers (In-place).
185. Partition Array to Place All Negative Numbers Before Positive Numbers (In-place).
186. Find First Element whose Value is Not Equal to its Index.
187. Find Last Element whose Value is Not Equal to its Index.
188. Find Number of Shifts Required to Match Another Array.
189. Count All Pairs `(i,j)` with `i<j` and `A[i] > A[j]`.
190. Count All Pairs `(i,j)` with `i<j` and `A[i] < A[j]`.
191. Count All Pairs `(i,j)` with `i<j` and `A[i] == A[j]`.
192. Count All Pairs `(i,j)` with `i<j` and `A[i] + A[j]` is Even.
193. Count All Pairs `(i,j)` with `i<j` and `A[i] + A[j]` is Odd.
194. Count All Pairs `(i,j)` with `i<j` and `A[i] * A[j]` is Even.
195. Count All Pairs `(i,j)` with `i<j` and `A[i] * A[j]` is Odd.
196. Find the Longest Alternating Subarray (even/odd).
197. Find the Longest Alternating Subarray (positive/negative).
198. Find the Smallest Number of Swaps to Sort an Array.
199. Find the Maximum Number of Swaps to Sort an Array (if allowed specific swaps).
200. Check if an Array Represents a Valid Permutation of 1 to N.
201. Find the Missing Number in an Array (Summation Method).
202. Find the Duplicate Number in an Array (Summation Method).
203. Find all duplicate numbers in an array (Negative Marking).
204. Find the first occurrence of a number whose index is equal to its value.
205. Find the last occurrence of a number whose index is equal to its value.
206. Find the Longest Increasing Subsequence (N log N).
207. Find the Longest Decreasing Subsequence (N log N).
208. Remove all elements that appear an odd number of times.
209. Remove all elements that appear an even number of times.
210. Find a pair `(i,j)` such that `A[i] == K * A[j]` for some `K`.
211. Find a pair `(i,j)` such that `A[i]` and `A[j]` have opposite parities.
212. Find a pair `(i,j)` such that `A[i]` and `A[j]` have the same parity.
213. Find the longest subarray with at most K distinct elements (two pointers).
214. Find the longest subarray with exactly K distinct elements (two pointers).
215. Find the smallest subarray with sum greater than or equal to target (two pointers).
216. Find the smallest window in a string containing all characters of another string (two
pointers).
217. Find the maximum element in each window of size K (deque/two pointers).
218. Find the minimum element in each window of size K (deque/two pointers).
219. Count subarrays with sum K (optimized with prefix sum and hash map).
220. Count subarrays with equal number of 0s and 1s (optimized with hash map).
221. Find the maximum subarray sum in a circular array (Kadane's + two pointers).
222. Find the maximum product subarray (Kadane's variant).
223. Count pairs `(i, j)` with `i < j` such that `A[i] + A[j]` is divisible by `K`.
224. Count triplets `(i, j, k)` with `i < j < k` such that `A[i] + A[j] + A[k]` is divisible by `K`.
225. Find maximum subarray sum with at least `K` elements.
226. Find maximum subarray sum with exactly `K` elements.
227. Find maximum subarray sum with at most `K` elements.
228. Find the element which appears `K` times (all others appear `M` times).
229. Find the Kth largest element in a stream (using priority queue).
230. Find the Kth smallest element in a stream (using priority queue).
231. Find median of a stream of numbers (using two heaps).
232. Maximize `A[i] - A[j]` where `i < j` and `A[i]` is even, `A[j]` is odd.
233. Maximize `A[i] - A[j]` where `i < j` and `A[i]` is odd, `A[j]` is even.
234. Maximize `A[i] + A[j]` where `i < j` and `A[i]` is even, `A[j]` is odd.
235. Maximize `A[i] + A[j]` where `i < j` and `A[i]` is odd, `A[j]` is even.
236. Count Subarrays with a specific average value.
237. Find the longest subarray with a specific average value.
238. Find all pairs `(i, j)` where `A[i]` is prime and `A[j]` is composite.
239. Find all pairs `(i, j)` where `A[i]` and `A[j]` are both prime.
240. Find all pairs `(i, j)` where `A[i]` and `A[j]` are both composite.
241. Count subarrays whose elements are all positive.
242. Count subarrays whose elements are all negative.
243. Find longest subarray whose elements are all positive.
244. Find longest subarray whose elements are all negative.
245. Find the maximum number of items that can be collected with a specific weight limit
(knapsack variant with array elements).
246. Find the minimum cost to reach the end of an array (jumps allowed, DP intro).
247. Count paths from start to end (with specific jump rules, DP intro).
248. Find the longest path in an array where each step increases the value by 1.
249. Find the shortest path in an array where each step decreases the value by 1.
250. Check if an array is a valid mountain array.
251. Find the peak index in a mountain array.
252. Find all peak indices in an array.
253. Find all valley indices in an array.
254. Count elements greater than their right neighbor.
255. Count elements smaller than their right neighbor.
256. Count elements greater than their left neighbor.
257. Count elements smaller than their left neighbor.
258. Find first element that is a local maximum.
259. Find first element that is a local minimum.
260. Find last element that is a local maximum.
261. Find last element that is a local minimum.
262. Find the minimum number of swaps to sort an array containing elements from 1 to N.
263. Find the minimum number of reversals to sort a binary array.
264. Find the minimum number of adjacent swaps to sort an array.
265. Find the maximum number of adjacent swaps to sort an array.
266. Check if an array can be made sorted by reversing exactly one subarray.
267. Check if an array can be made sorted by performing exactly one swap.
268. Find the maximum difference between two elements such that the larger element appears
after the smaller element.
269. Find the maximum difference between two elements such that the smaller element appears
after the larger element.
270. Find the minimum difference between two elements such that the larger element appears
after the smaller element.
271. Find the minimum difference between two elements such that the smaller element appears
after the larger element.
272. Find the number of pairs `(i, j)` such that `i < j` and `A[j] - A[i] == K`.
273. Find the number of pairs `(i, j)` such that `i < j` and `A[j] - A[i] > K`.
274. Find the number of pairs `(i, j)` such that `i < j` and `A[j] - A[i] < K`.
275. Find the longest subarray where all elements are powers of 2.
276. Count subarrays where all elements are powers of 2.
277. Find the longest subarray where all elements are prime numbers.
278. Count subarrays where all elements are prime numbers.
279. Find the longest subarray where all elements are composite numbers.
280. Count subarrays where all elements are composite numbers.
281. Find the maximum sum subarray where all elements are distinct.
282. Find the minimum sum subarray where all elements are distinct.
283. Count subarrays where all elements are distinct.
284. Count subarrays with sum `K` and all elements are distinct.
285. Count subarrays with sum `K` and all elements are positive.
286. Count subarrays with sum `K` and all elements are negative.
287. Find the longest subarray whose sum is `K` and all elements are distinct.
288. Find the longest subarray whose sum is `K` and all elements are positive.
289. Find the longest subarray whose sum is `K` and all elements are negative.
290. Find the smallest subarray whose sum is `K` and all elements are distinct.
291. Find the smallest subarray whose sum is `K` and all elements are positive.
292. Find the smallest subarray whose sum is `K` and all elements are negative.
293. Find the maximum length of a subarray where the values are consecutive (e.g., `[3, 1, 2]` is
valid).
294. Find the minimum length of a subarray where the values are consecutive.
295. Count subarrays where the values are consecutive.
296. Find the maximum product subarray where all elements are positive.
297. Find the maximum product subarray where all elements are negative.
298. Find the minimum product subarray where all elements are positive.
299. Find the minimum product subarray where all elements are negative.
300. Find the number of inversions in a subarray `[L, R]`.

#### 3. Prefix Sum & Difference Array (Approx. 300 Problems)

**Prefix Sum Core Concepts:**


1. Generate Prefix Sum Array from Input.
2. Generate Prefix Product Array from Input.
3. Generate Prefix XOR Array from Input.
4. Perform Range Sum Query `[L, R]` on Static Array.
5. Perform Range Product Query `[L, R]` on Static Array.
6. Perform Range XOR Query `[L, R]` on Static Array.
7. Count Subarrays with Sum Equal to Target.
8. Find Longest Subarray with Sum Equal to Target.
9. Count Subarrays with Sum Less Than Target.
10. Count Subarrays with Sum Greater Than Target.
11. Find Longest Subarray with Sum Less Than Target.
12. Find Longest Subarray with Sum Greater Than Target.
13. Count Subarrays Whose Sum is Divisible by M.
14. Find Longest Subarray Whose Sum is Divisible by M.
15. Find Equi-Partition Index for Equal Sums.
16. Count Ways to Split Array into Three Equal Sum Parts.
17. Count Binary Subarrays with Target Sum.
18. Determine Minimum Start Value for Positive Step-by-Step Sum.
19. Implement Product of Array Except Self using Prefix/Suffix Products.
20. Decode XORed Array Given First Element (using Prefix XOR).
21. Compute Running Sum of 1D Array.
22. Find Maximize `A[i] + A[j] + (j-i)` (using prefix sums for `A[i]-i` and `A[j]+j`).
23. Find Maximum Average Subarray of Fixed Length K (Sliding Window + Prefix Sum).
24. Perform Range Sum Query on Permutation Array.
25. Count Subarrays with Given Sum and Fixed Length K.
26. Find Longest Subarray with Sum Less Than or Equal to K.
27. Find Longest Subarray with Sum Greater Than or Equal to K.
28. Count Subarrays with Sum in a Given Range `[L, R]`.
29. Find Max Sum Subarray Consisting Only of Positive Numbers (Prefix Sum + Max tracking).
30. Find Min Sum Subarray Consisting Only of Negative Numbers (Prefix Sum + Min tracking).

**Prefix Sum for Complex Patterns:**


31. Determine if Subarray with Zero Sum Exists.
32. Find Indices of All Subarrays with Zero Sum.
33. Count Subarrays with Zero Sum.
34. Count Pairs `(i, j)` where `i < j` and `PrefixSum[j] == PrefixSum[i]`.
35. Count Subarrays with Equal Number of 0s and 1s.
36. Find Longest Subarray with Equal Number of 0s and 1s.
37. Count Subarrays with Equal Number of 0s, 1s, and 2s.
38. Find Longest Subarray with Equal Number of 0s, 1s, and 2s.
39. Count Subarrays Whose XOR Sum is K.
40. Find Longest Subarray Whose XOR Sum is K.
41. Find Number of Subarrays with Product K.
42. Find Longest Subarray with Product K.
43. Count Subarrays with Product Less Than K.
44. Find Longest Subarray with Product Less Than K.
45. Count Pairs `(i, j)` where `i < j` and `PrefixProduct[j] == PrefixProduct[i]`.
46. Count Pairs `(i, j)` where `i < j` and `PrefixXOR[j] == PrefixXOR[i]`.
47. Count Subarrays where Sum is a Fibonacci Number.
48. Find Longest Subarray where Sum is a Fibonacci Number.
49. Count Subarrays where Sum is a Prime Number.
50. Find Longest Subarray where Sum is a Prime Number.

**Difference Array Core Concepts:**


51. Generate Difference Array from Input.
52. Apply Single Range Increment `(start, end, value)` to Difference Array.
53. Apply Multiple Range Increments using Difference Array, then Reconstruct Array.
54. Determine Final Array after K Range Additions.
55. Check Car Pooling Feasibility (Difference Array on Time intervals).
56. Find Year with Maximum Population (Difference Array on Years).
57. Aggregate Flight Bookings (Difference Array on Flight Numbers).
58. Perform Range Update and Point Query using Difference Array.
59. Perform Range Update and Range Query using Difference Array.
60. Range Update and Maximum Element Query (Difference Array with additional data structure).
61. Range Update and Minimum Element Query (Difference Array with additional data structure).
62. Range Set Value Operation (Adaptation using Difference Array).
63. Count Inversions after K Range Updates.
64. Find Array Elements Equal to Their Indices after Range Updates.
65. Determine if Array Becomes Strictly Increasing after Range Updates.
66. Determine if Array Becomes Sorted after Range Updates.
67. Calculate Total Value After Point Updates, Sum Over All Ranges.
68. Find Max Value in Array after Interval Increments.
69. Find Min Value in Array after Interval Increments.
70. Count Peaks in Array after Interval Increments.
71. Count Valleys in Array after Interval Increments.
72. Simulate Overlapping Intervals and find Maximum Overlap Count.
73. Find Maximum Number of Active Intervals at any Point.
74. Find Total Length of Union of Intervals.
75. Count Points Covered by At Least One Interval.
76. Count Points Covered by Exactly K Intervals.
77. Implement Difference Array on a Circular Array.
78. Apply Range Updates to a Circular Array.
79. Maximize Score in Game with Interval Bonuses (Difference Array for bonuses).
80. Minimize Cost to Adjust Array to Target Values using Range Operations.

**2D Prefix Sum / Difference Array:**


81. Construct 2D Prefix Sum Matrix.
82. Perform 2D Range Sum Query (Rectangular Region).
83. Calculate Matrix Block Sum (Sum of KxK submatrix around each cell).
84. Count Submatrices with Target Sum.
85. Count Square Submatrices with Target Sum.
86. Count Submatrices with All Ones.
87. Find Largest Sum Rectangular Submatrix.
88. Find Largest Sum Rectangular Submatrix Not Exceeding K.
89. Implement 2D Difference Array for Rectangular Region Updates.
90. Apply Multiple 2D Range Updates, then Reconstruct Matrix.
91. Calculate Maximum Population Density in a 2D Grid (Difference Array).
92. Count Points within Rectangles using 2D Prefix Sums.
93. Find Largest Square Submatrix with Sum Less Than or Equal to K.
94. Find Largest Rectangular Submatrix with Sum Less Than or Equal to K.
95. Find All Submatrices with a Sum of Zero.
96. Count Rectangular Regions with a Given Average.
97. Find the Number of Ways to Divide a Grid into K Rectangular Parts with Specific Sums.
98. Count Islands after adding or removing elements (dynamic grid using 2D difference array).
99. Find Longest Path in a Binary Matrix (can use 2D prefix concepts for value changes).
100. Count Number of Paths in Grid with Sum K (2D Prefix DP).

**Complex Combinations & Variants:**


101. Maximum Sum of Two Non-Overlapping Subarrays (Fixed Lengths L and M).
102. Maximum Sum of Three Non-Overlapping Subarrays (Fixed Lengths L, M, N).
103. Maximum Sum of K Non-Overlapping Subarrays (Fixed Lengths).
104. Maximum Sum of K Non-Overlapping Subarrays (Variable Lengths).
105. Minimize Max Value of Partitioned Array (K Partitions).
106. Maximize Min Value of Partitioned Array (K Partitions).
107. Count Partitions into K Subarrays with Equal Sum.
108. Maximize Value of Expression `A[i] + A[j] + A[k]` where `i < j < k`.
109. Minimize Value of Expression `A[i] + A[j] + A[k]` where `i < j < k`.
110. Maximum Sum of Subarray with Bounded Length `[L, R]`.
111. Minimum Sum of Subarray with Bounded Length `[L, R]`.
112. Max Score by Choosing K Elements from Front or Back (Sliding Window + Prefix Sum).
113. Count Valid Parentheses Substrings (Prefix sum for balance).
114. Find Longest Valid Parentheses Substring (Prefix sum for balance).
115. Balance Array to Make Sum Zero with Minimum Operations.
116. Calculate Profit for Stock Trading (K transactions, Prefix Sum for max/min up to point).
117. Find Number of Pairs `(i, j)` where `i < j` and `prefixSum[j] - prefixSum[i-1]` is a perfect
square.
118. Count Subarrays where XOR Sum is greater than K.
119. Count Subarrays where XOR Sum is less than K.
120. Find Longest Subarray where Sum of elements equals Sum of Indices.
121. Count Subarrays where Sum of elements equals Sum of Indices.
122. Count Subarrays where Sum is a Prime Number (using Prefix Sum and Sieve).
123. Count Subarrays where Sum is a Composite Number (using Prefix Sum and Sieve).
124. Calculate Sum of Minimums of All Subarrays (Monotonic Stack + Prefix Sum).
125. Calculate Sum of Maximums of All Subarrays (Monotonic Stack + Prefix Sum).
126. Count Good Subarrays (definition involves prefix sums like sum within range).
127. Count Number of Subarrays with Bounded Range `(max - min <= K)`.
128. Find Longest Subarray with Bounded Range `(max - min <= K)`.
129. Count Subarrays where `max - min` is exactly K.
130. Count Subarrays with a Specific XOR value K.
131. Find the Maximum XOR sum of any Subarray.
132. Find the Minimum XOR sum of any Subarray.
133. Find the Number of Ways to Form a Target Sum Using Subarray Elements (DP with prefix
sums).
134. Count Subarrays where Average is Exactly K.
135. Find Longest Subarray where Average is Exactly K.
136. Count Subarrays where Average is Less Than K.
137. Count Subarrays where Average is Greater Than K.
138. Find the Longest Subarray where the Sum of elements is `N * K` (N is length).
139. Find the Smallest Subarray where the Sum of elements is `N * K`.
140. Count Indices `i` such that sum of `A[0...i]` equals sum of `A[i+1...N-1]`.
141. Find Maximum Number of Nested Sum Intervals.
142. Find Minimum Number of Overlapping Sum Intervals.
143. Calculate Number of Subarrays with Sum in a Given Range (Advanced Prefix Sum + Tree/
Fenwick).
144. Find a Subarray Whose Sum is Closest to K (Prefix Sum + Binary Search/Segment Tree).
145. Count Subarrays with Odd Number of Even Elements.
146. Count Subarrays with Even Number of Odd Elements.
147. Find Longest Subarray with Sum Equal to `K * Length`.
148. Count Subarrays where Product of Elements is a Perfect Square.
149. Count Subarrays where Product of Elements is a Prime Number.
150. Count Subarrays where XOR Sum is 0.
151. Count Subarrays where Max Element is Less Than Min Element (Conceptual).
152. Find Max Sum of `A[i] + B[j] + C[k]` where `i < j < k` from three arrays (using prefix max/min).
153. Count the number of subarrays whose elements, when sorted, form an arithmetic
progression.
154. Count the number of subarrays that contain a specific target element `X` exactly `K` times.
155. Find the longest subarray that contains at most `K` occurrences of each distinct element.
156. Find the number of pairs `(i, j)` such that `i < j` and `array[j] - array[i] == K`.
157. Find the number of triplets `(i, j, k)` such that `i < j < k` and `array[j] - array[i] == K` and
`array[k] - array[j] == K`.
158. Calculate the sum of `min(A[i], A[j])` for all pairs `(i, j)` where `i < j` (using prefix sums for
intervals).
159. Calculate the sum of `max(A[i], A[j])` for all pairs `(i, j)` where `i < j` (using prefix sums for
intervals).
160. Find the longest subarray such that the number of even elements equals the number of odd
elements.
161. Count subarrays such that the number of even elements equals the number of odd
elements.
162. Find the maximum value of `A[i] XOR A[j]` for all `i < j` (Prefix XOR properties).
163. Find the minimum value of `A[i] XOR A[j]` for all `i < j` (Prefix XOR properties).
164. Count pairs `(i, j)` such that `i < j` and `A[i]` is a factor of `A[j]`.
165. Count pairs `(i, j)` such that `i < j` and `A[j]` is a multiple of `A[i]`.
166. Find the longest subarray such that all elements are distinct and form a consecutive
sequence (using prefix sum hash for checks).
167. Count subarrays where the product of elements is negative.
168. Find the longest subarray where `max(window) - min(window)` is exactly `K`.
169. Count Subarrays with `max(element) - min(element)` equal to `K`.
170. Count Subarrays with `max(element) - min(element)` less than `K`.
171. Count Subarrays with `max(element) - min(element)` greater than `K`.
172. Find Longest Subarray with `max(element) - min(element)` less than or equal to `K`.
173. Find Longest Subarray with `max(element) - min(element)` greater than or equal to `K`.
174. Count Subarrays with a Bounded Product (using prefix product or logs).
175. Find the Maximum Sum of `array[i] * i` from `i=0` to `N-1` after any number of rotations.
176. Find the Minimum Sum of `array[i] * i` from `i=0` to `N-1` after any number of rotations.
177. Find All Possible Subarrays whose sum is a Fibonacci Number.
178. Count Subarrays such that the sum of elements is equal to the sum of their indices.
179. Find Max Sum of `A[i] + B[j] + C[k]` where `i < j < k` from three arrays (using Prefix Max/Min).
180. Count the number of subarrays whose elements, when sorted, form an arithmetic
progression.
181. Count the number of subarrays that contain a specific target element `X` exactly `K` times.
182. Find the longest subarray that contains at most `K` occurrences of each distinct element.
183. Find the number of pairs `(i, j)` such that `i < j` and `array[j] - array[i] == K`.
184. Find the number of triplets `(i, j, k)` such that `i < j < k` and `array[j] - array[i] == K` and
`array[k] - array[j] == K`.
185. Calculate the sum of `min(A[i], A[j])` for all pairs `(i, j)` where `i < j`.
186. Calculate the sum of `max(A[i], A[j])` for all pairs `(i, j)` where `i < j`.
187. Find the longest subarray such that the number of even elements equals the number of odd
elements.
188. Count subarrays such that the number of even elements equals the number of odd
elements.
189. Find the maximum value of `A[i] XOR A[j]` for all `i < j`.
190. Find the minimum value of `A[i] XOR A[j]` for all `i < j`.
191. Count pairs `(i, j)` such that `i < j` and `A[i]` is a factor of `A[j]`.
192. Count pairs `(i, j)` such that `i < j` and `A[j]` is a multiple of `A[i]`.
193. Find the longest subarray such that all elements are distinct and form a consecutive
sequence.
194. Count subarrays where the product of elements is negative.
195. Find the maximum length of a subarray where the values are consecutive.
196. Find the minimum length of a subarray where the values are consecutive.
197. Count subarrays where the values are consecutive.
198. Find the maximum product subarray where all elements are positive.
199. Find the maximum product subarray where all elements are negative.
200. Find the minimum product subarray where all elements are positive.
201. Find the minimum product subarray where all elements are negative.
202. Maximize `A[i] + B[j] + C[k]` where `i < j < k` from three arrays (Prefix sum for pairs).
203. Maximize `A[i] + B[j] + C[k] + D[l]` where `i < j < k < l` from four arrays (Prefix sum).
204. Count pairs `(i,j)` such that `prefix_sum[j] - prefix_sum[i-1]` is a prime number.
205. Count triplets `(i,j,k)` such that `prefix_sum[j] - prefix_sum[i-1]` and `prefix_sum[k] -
prefix_sum[j-1]` are primes.
206. Find longest subarray with `max - min <= K` using two pointers and prefix sums for range
queries on min/max.
207. Count subarrays with a given sum `K` in a circular array.
208. Find longest subarray with a given sum `K` in a circular array.
209. Find shortest subarray with a given sum `K` in a circular array.
210. Count pairs `(i, j)` such that `i < j` and `(prefix_sum[j] - prefix_sum[i-1]) % M == 0`.
211. Find max product subarray using prefix products and handling zero/negative values.
212. Find max XOR subarray using prefix XORs and a Trie (advanced).
213. Find subarray with target sum closest to `K`.
214. Count subarrays whose sums are perfect squares.
215. Count subarrays whose sums are powers of two.
216. Find longest subarray whose sums are perfect squares.
217. Find longest subarray whose sums are powers of two.
218. Count subarrays where the sum of `A[i] / i` is equal to target.
219. Find longest subarray where the sum of `A[i] / i` is equal to target.
220. Count subarrays where sum of `A[i]` is equal to sum of `A[j]` for `i < j`.
221. Find max sum of `A[i] - A[j]` for `i < j` using prefix minimums.
222. Find max sum of `A[i] + A[j]` for `i < j` using prefix maximums.
223. Count subarrays where all elements are positive and sum is `K`.
224. Count subarrays where all elements are negative and sum is `K`.
225. Find the minimum length subarray with sum `K` (using prefix sums and hash map).
226. Count pairs `(i, j)` such that `prefix_sum[i]` and `prefix_sum[j]` have a common factor.
227. Find longest subarray where `max(window) - min(window)` is minimized (not fixed `K`).
228. Find smallest subarray where `max(window) - min(window)` is minimized.
229. Count subarrays where the first and last elements are equal and sum is `K`.
230. Find longest subarray where first and last elements are equal and sum is `K`.
231. Maximize `(j-i) * (prefix_sum[j] - prefix_sum[i-1])` for `i < j`.
232. Minimize `(j-i) * (prefix_sum[j] - prefix_sum[i-1])` for `i < j`.
233. Find longest subarray with sum `K` (can contain negative numbers).
234. Find shortest subarray with sum `K` (can contain negative numbers).
235. Count subarrays whose sum is an even number.
236. Count subarrays whose sum is an odd number.
237. Find the number of subarrays whose elements' product is negative.
238. Find the longest subarray whose elements' product is negative.
239. Find the number of subarrays whose elements' product is positive.
240. Find the longest subarray whose elements' product is positive.
241. Count subarrays whose elements' XOR sum is even.
242. Count subarrays whose elements' XOR sum is odd.
243. Find the number of subarrays where `prefix_sum[j] > prefix_sum[i]` for `j > i`.
244. Find the number of subarrays where `prefix_sum[j] < prefix_sum[i]` for `j > i`.
245. Find the longest subarray where `prefix_sum[j] > prefix_sum[i]` for `j > i`.
246. Find the longest subarray where `prefix_sum[j] < prefix_sum[i]` for `j > i`.
247. Count subarrays where the median of the subarray elements is exactly `K`.
248. Find the longest subarray where the median of the subarray elements is exactly `K`.
249. Count subarrays where the mode of the subarray elements is exactly `K`.
250. Find the longest subarray where the mode of the subarray elements is exactly `K`.
251. Find the number of triplets `(i, j, k)` such that `prefix_sum[i]`, `prefix_sum[j]`, `prefix_sum[k]`
form an arithmetic progression.
252. Find the number of quadruplets `(i, j, k, l)` such that `prefix_sum[i]`, `prefix_sum[j]`,
`prefix_sum[k]`, `prefix_sum[l]` form an arithmetic progression.
253. Find the longest subarray where the number of even elements in its prefix is greater than the
number of odd elements.
254. Find the longest subarray where the number of even elements in its prefix is less than the
number of odd elements.
255. Count subarrays such that the sum of elements is equal to `K` times its length.
256. Find the longest subarray such that the sum of elements is equal to `K` times its length.
257. Count subarrays where the product of elements is equal to `K` times its length.
258. Find the longest subarray where the product of elements is equal to `K` times its length.
259. Find maximum XOR value of `(prefix_sum[j] XOR prefix_sum[i-1])` for `j > i`.
260. Find minimum XOR value of `(prefix_sum[j] XOR prefix_sum[i-1])` for `j > i`.
261. Count subarrays where sum is `K` and elements are distinct (uses prefix sums + sliding
window/hash).
262. Find longest subarray where sum is `K` and elements are distinct (uses prefix sums + sliding
window/hash).
263. Count subarrays where `max(prefix_sum[j], prefix_sum[i]) - min(prefix_sum[j], prefix_sum[i])`
is `K`.
264. Find longest subarray where `max(prefix_sum[j], prefix_sum[i]) - min(prefix_sum[j],
prefix_sum[i])` is `K`.
265. Count pairs `(i, j)` such that `i < j` and `(prefix_sum[j] - prefix_sum[i-1])` is less than `K`.
266. Count pairs `(i, j)` such that `i < j` and `(prefix_sum[j] - prefix_sum[i-1])` is greater than `K`.
267. Count pairs `(i, j)` such that `i < j` and `(prefix_sum[j] - prefix_sum[i-1])` is a perfect number.
268. Find the number of triplets `(i, j, k)` such that `i < j < k` and `prefix_sum[i] + prefix_sum[j] ==
prefix_sum[k]`.
269. Find the number of triplets `(i, j, k)` such that `i < j < k` and `prefix_sum[i] XOR prefix_sum[j]
== prefix_sum[k]`.
270. Find the maximum length of a subarray whose prefix sums are all even.
271. Find the maximum length of a subarray whose prefix sums are all odd.
272. Find the minimum length of a subarray whose prefix sums are all even.
273. Find the minimum length of a subarray whose prefix sums are all odd.
274. Count subarrays where the prefix sum is a prime number.
275. Count subarrays where the prefix sum is a composite number.
276. Find the maximum sum subarray where all prefix sums are non-negative.
277. Find the minimum sum subarray where all prefix sums are non-negative.
278. Count subarrays where all prefix sums are non-negative.
279. Count subarrays where all prefix sums are positive.
280. Find the maximum value of `A[i] + A[j] + A[k] - (j-i) - (k-j)` for `i < j < k` using prefix sums.
281. Find the maximum value of `A[i] + A[j] + A[k] + (j-i) + (k-j)` for `i < j < k` using prefix sums.
282. Find the minimum value of `A[i] + A[j] + A[k] - (j-i) - (k-j)` for `i < j < k` using prefix sums.
283. Find the minimum value of `A[i] + A[j] + A[k] + (j-i) + (k-j)` for `i < j < k` using prefix sums.
284. Count pairs `(i,j)` such that `i < j` and `A[i]` is a factor of `prefix_sum[j] - prefix_sum[i-1]`.
285. Count pairs `(i,j)` such that `i < j` and `A[j]` is a multiple of `prefix_sum[j] - prefix_sum[i-1]`.
286. Find the longest subarray where the sum of elements is equal to the sum of its indices,
using prefix sums.
287. Find the shortest subarray where the sum of elements is equal to the sum of its indices,
using prefix sums.
288. Count subarrays where the product of elements is a prime number (using prefix products for
checks).
289. Count subarrays where the product of elements is a composite number (using prefix
products for checks).
290. Count subarrays where `prefix_sum[i]` is strictly increasing.
291. Count subarrays where `prefix_sum[i]` is strictly decreasing.
292. Find the longest subarray where `prefix_sum[i]` is strictly increasing.
293. Find the longest subarray where `prefix_sum[i]` is strictly decreasing.
294. Find the number of subarrays whose prefix sums alternate in parity.
295. Find the longest subarray whose prefix sums alternate in parity.
296. Find the number of subarrays whose prefix sums alternate in sign.
297. Find the longest subarray whose prefix sums alternate in sign.
298. Count subarrays whose elements sum to `K` using `O(1)` space (if constraints allow, e.g.
positive numbers only).
299. Find the number of times a `prefix_sum` appears in the array.
300. Find the maximum number of times any `prefix_sum` appears in the array.

#### 4. Subarrays & Subsequence Basics (Approx. 300 Problems)

**Subarray Generation & Properties:**


1. Enumerate All Contiguous Subarrays.
2. Count Total Contiguous Subarrays.
3. Count Contiguous Subarrays of Even Length.
4. Count Contiguous Subarrays of Odd Length.
5. Find All Subarrays Containing Specific Element.
6. Count Subarrays Containing Specific Element.
7. Find Smallest Subarray Containing Specific Element.
8. Find Largest Subarray Containing Specific Element.
9. Enumerate All Subarrays where All Elements are Positive.
10. Count Subarrays where All Elements are Positive.
11. Enumerate All Subarrays where All Elements are Negative.
12. Count Subarrays where All Elements are Negative.
13. Enumerate All Subarrays where All Elements are Zero.
14. Count Subarrays where All Elements are Zero.
15. Find Longest Subarray with Alternating Positive/Negative Signs.
16. Find Longest Subarray with Alternating Even/Odd Parity.
17. Count Subarrays where Product is 1.
18. Count Subarrays where XOR Sum is 0.
19. Find Longest Subarray with Exactly K Even Numbers.
20. Find Longest Subarray with Exactly K Odd Numbers.
21. Count Subarrays with Exactly K Distinct Elements.
22. Count Subarrays with At Most K Distinct Elements.
23. Count Subarrays with At Least K Distinct Elements.
24. Find Longest Subarray with Exactly K Distinct Elements.
25. Find Longest Subarray with At Most K Distinct Elements.
26. Find Longest Subarray with At Least K Distinct Elements.
27. Count Subarrays Where Maximum Element is K.
28. Count Subarrays Where Minimum Element is K.
29. Enumerate All Subarrays whose Sum is a Multiple of K.
30. Find Longest Subarray whose Sum is a Multiple of K.
31. Count Subarrays with Sum in a Given Range `[L, R]`.
32. Find Longest Subarray with Sum in a Given Range `[L, R]`.
33. Find Shortest Subarray with Sum in a Given Range `[L, R]`.
34. Count Subarrays that are Sorted Non-decreasingly.
35. Count Subarrays that are Sorted Non-increasingly.
36. Find Longest Subarray that is Sorted Non-decreasingly.
37. Find Longest Subarray that is Sorted Non-increasingly.
38. Count Subarrays with All Unique Elements.
39. Find Longest Subarray with All Unique Elements.
40. Count Subarrays with Bounded Average.
41. Find Longest Subarray with Bounded Average.
42. Count Subarrays Where Product of Elements is Positive.
43. Count Subarrays Where Product of Elements is Negative.
44. Count Subarrays Where Product of Elements is Zero.
45. Find Longest Subarray Where Product of Elements is Positive.
46. Find Longest Subarray Where Product of Elements is Negative.
47. Find Shortest Subarray Whose Sum is at Least K.
48. Count Subarrays Whose Sum is at Least K.
49. Find Longest Subarray Whose Sum is at Most K.
50. Count Subarrays Whose Sum is at Most K.

**Subsequence Generation & Properties:**


51. Enumerate All Possible Subsequences.
52. Count Total Possible Subsequences.
53. Find All Subsequences that are Sorted Non-decreasingly.
54. Count Subsequences that are Sorted Non-decreasingly.
55. Find Longest Increasing Subsequence Length (DP).
56. Find Longest Decreasing Subsequence Length (DP).
57. Find Longest Non-Decreasing Subsequence Length (DP).
58. Find Longest Non-Increasing Subsequence Length (DP).
59. Count Subsequences with Sum Less Than or Equal to Target.
60. Count Subsequences with Sum Exactly Equal to Target.
61. Count Subsequences with Sum Greater Than or Equal to Target.
62. Maximum Sum Subsequence with No Adjacent Elements.
63. Maximum Product Subsequence with No Adjacent Elements.
64. Find All Subsequences with a Given Sum (Backtracking).
65. Count Palindromic Subsequences.
66. Find Longest Palindromic Subsequence.
67. Count Unique Subsequences.
68. Find All Subsequences that are Palindromic.
69. Find All Subsequences with Alternating Parity.
70. Find Longest Subsequence with Alternating Parity.
71. Find All Subsequences with Alternating Signs.
72. Find Longest Subsequence with Alternating Signs.
73. Count Subsequences Where Each Element is a Multiple of Previous.
74. Count Subsequences Where Each Element is a Factor of Previous.
75. Find Longest Subsequence Where Each Element is a Multiple of Previous.
76. Find Longest Subsequence Where Each Element is a Factor of Previous.
77. Count Subsequences Where Elements are Consecutive Integers.
78. Find Longest Subsequence Where Elements are Consecutive Integers.
79. Count Subsequences with Difference Between Max and Min <= K.
80. Find Longest Subsequence with Difference Between Max and Min <= K.

**Combined & Advanced Problems:**


81. Count Pairs `(i, j)` where `i < j` and `Array[i] == Array[j]`.
82. Count Arithmetic Contiguous Subarrays (Slices).
83. Count Arithmetic Subsequences.
84. Smallest Range After Value Adjustments (Each element `x +/- k`).
85. Maximum Length of Subarray with Positive Product.
86. Count Square Submatrices with All Ones.
87. Count Substrings with Only One Distinct Character.
88. Array Partition for Minimum Sum of `min(pair)`.
89. Find Shortest Subarray with Max Frequency (Degree of Array).
90. Count Subarrays where `max - min` is less than K.
91. Count Subarrays where `max - min` is greater than K.
92. Count Subarrays where `max - min` is exactly K.
93. Find Longest Subarray where `max - min` is less than or equal to K.
94. Find Longest Subarray where `max - min` is greater than or equal to K.
95. Find Longest Common Subsequence of Two Arrays.
96. Find Shortest Common Supersequence of Two Arrays.
97. Count Subsequences of Length K with Sum S.
98. Find All Subsequences of Length K with Sum S.
99. Count Subsequences where Average is K.
100. Find Longest Subsequence where Average is K.
101. Count Subsequences Where XOR Sum is K.
102. Find Longest Subsequence Where XOR Sum is K.
103. Count Subsequences with Only Unique Elements.
104. Find Longest Subsequence with Only Unique Elements.
105. Count Subsequences Where All Elements are Identical.
106. Find Longest Subsequence Where All Elements are Identical.
107. Count Subsequences Where Product is K.
108. Find Longest Subsequence Where Product is K.
109. Count Subsequences with an Even Sum.
110. Count Subsequences with an Odd Sum.
111. Count Subarrays with an Even Sum.
112. Count Subarrays with an Odd Sum.
113. Count Subarrays with an Even Product.
114. Count Subarrays with an Odd Product.
115. Find Longest Subarray with an Even Sum.
116. Find Longest Subarray with an Odd Sum.
117. Find Longest Subarray with an Even Product.
118. Find Longest Subarray with an Odd Product.
119. Count Subarrays where All Elements are Prime.
120. Find Longest Subarray where All Elements are Prime.
121. Count Subarrays where All Elements are Fibonacci Numbers.
122. Find Longest Subarray where All Elements are Fibonacci Numbers.
123. Count Subarrays that are Palindromic (String View).
124. Find Longest Palindromic Substring (Manacher's).
125. Count Palindromic Substrings.
126. Count Distinct Palindromic Substrings.
127. Count Subsequences of Length K where elements are distinct.
128. Find Longest Subsequence of Length K where elements are distinct.
129. Count Subsequences where the sum of `max` and `min` elements is `K`.
130. Find Longest Subsequence where the sum of `max` and `min` elements is `K`.
131. Count Subsequences where `max(element) - min(element)` is maximized.
132. Find Longest Subsequence where `max(element) - min(element)` is maximized.
133. Count Subsequences that are Bitonic.
134. Find Longest Subsequence that is Bitonic.
135. Count Subsequences with Alternating Parity and Fixed Length K.
136. Find Longest Subsequence with Alternating Parity and Fixed Length K.
137. Count Subsequences where all elements are powers of 2.
138. Find Longest Subsequence where all elements are powers of 2.
139. Count Subsequences where adjacent elements are `A[i] = A[i-1] + 1`.
140. Find Longest Subsequence where adjacent elements are `A[i] = A[i-1] + 1`.
141. Count Subsequences with a Sum `S` from unique elements.
142. Find All Subsequences with a Sum `S` from unique elements.
143. Count Subsequences where the Product is even.
144. Count Subsequences where the Product is odd.
145. Find Longest Subsequence where the Product is even.
146. Find Longest Subsequence where the Product is odd.
147. Count Subsequences whose XOR sum is even.
148. Count Subsequences whose XOR sum is odd.
149. Find Longest Subsequence whose XOR sum is even.
150. Find Longest Subsequence whose XOR sum is odd.
151. Count Subarrays where the first element equals the last element.
152. Find Longest Subarray where the first element equals the last element.
153. Count Subarrays where the number of even elements is equal to the number of odd
elements.
154. Find Longest Subarray where the number of even elements is equal to the number of odd
elements.
155. Count Subarrays where the number of positive elements is equal to the number of negative
elements.
156. Find Longest Subarray where the number of positive elements is equal to the number of
negative elements.
157. Count Subarrays where the elements form a consecutive sequence (values differ by 1).
158. Find Longest Subarray where the elements form a consecutive sequence.
159. Count Subarrays that are permutations of `1` to `K`.
160. Find Longest Subarray that is a permutation of `1` to `K`.
161. Count Subarrays where the sum of `max` and `min` elements is `K`.
162. Find Longest Subarray where the sum of `max` and `min` elements is `K`.
163. Count Subarrays where the absolute difference between any two elements is at most `K`.
164. Find Longest Subarray where the absolute difference between any two elements is at most
`K`.
165. Count Subarrays where `max(subarray) - min(subarray) == K`.
166. Find Longest Subarray where `max(subarray) - min(subarray) == K`.
167. Count Subarrays where `max(subarray) - min(subarray) < K`.
168. Find Longest Subarray where `max(subarray) - min(subarray) < K`.
169. Count Subarrays where `max(subarray) - min(subarray) > K`.
170. Find Longest Subarray where `max(subarray) - min(subarray) > K`.
171. Count Subarrays where the Product of its elements is `K`.
172. Find Longest Subarray where the Product of its elements is `K`.
173. Count Subarrays where the Product of its elements is less than `K`.
174. Find Longest Subarray where the Product of its elements is less than `K`.
175. Count Subarrays where the Product of its elements is greater than `K`.
176. Find Longest Subarray where the Product of its elements is greater than `K`.
177. Count Subarrays where the Average of elements is `K`.
178. Find Longest Subarray where the Average of elements is `K`.
179. Count Subarrays where the Average of elements is less than `K`.
180. Find Longest Subarray where the Average of elements is less than `K`.
181. Count Subarrays where the Average of elements is greater than `K`.
182. Find Longest Subarray where the Average of elements is greater than `K`.
183. Count Subarrays where the elements are sorted non-decreasingly (using sliding window).
184. Count Subarrays where the elements are sorted non-increasingly (using sliding window).
185. Find Longest Subarray where the elements are sorted non-decreasingly (using sliding
window).
186. Find Longest Subarray where the elements are sorted non-increasingly (using sliding
window).
187. Count Subarrays containing at least one occurrence of a specific value `X`.
188. Count Subarrays containing no occurrence of a specific value `X`.
189. Find Longest Subarray containing at least one occurrence of `X`.
190. Find Longest Subarray containing no occurrence of `X`.
191. Count Subarrays with a given XOR sum (using prefix XOR).
192. Find Longest Subarray with a given XOR sum (using prefix XOR).
193. Count Subarrays where `max(element) == K` and `min(element) == M`.
194. Find Longest Subarray where `max(element) == K` and `min(element) == M`.
195. Count Subarrays whose elements are all distinct and positive.
196. Find Longest Subarray whose elements are all distinct and positive.
197. Count Subarrays whose elements are all distinct and negative.
198. Find Longest Subarray whose elements are all distinct and negative.
199. Count Subarrays whose elements are all prime and distinct.
200. Find Longest Subarray whose elements are all prime and distinct.
201. Count Subarrays that are palindromic and have even length.
202. Count Subarrays that are palindromic and have odd length.
203. Find Longest Subarray that is palindromic and has even length.
204. Find Longest Subarray that is palindromic and has odd length.
205. Count Subarrays where the sum of elements is a multiple of `K` and length is even.
206. Count Subarrays where the sum of elements is a multiple of `K` and length is odd.
207. Find Longest Subarray where the sum of elements is a multiple of `K` and length is even.
208. Find Longest Subarray where the sum of elements is a multiple of `K` and length is odd.
209. Count Subarrays where the average is `K` and elements are distinct.
210. Find Longest Subarray where the average is `K` and elements are distinct.
211. Count Subsequences whose elements' product is a perfect square.
212. Count Subsequences whose elements' product is a prime number.
213. Find Longest Subsequence whose elements' product is a perfect square.
214. Find Longest Subsequence whose elements' product is a prime number.
215. Count Subsequences whose elements' XOR sum is a perfect square.
216. Count Subsequences whose elements' XOR sum is a prime number.
217. Find Longest Subsequence whose elements' XOR sum is a perfect square.
218. Find Longest Subsequence whose elements' XOR sum is a prime number.
219. Count Subarrays where the number of distinct elements is equal to its length.
220. Find Longest Subarray where the number of distinct elements is equal to its length.
221. Count Subarrays where the sum of its elements equals its length.
222. Find Longest Subarray where the sum of its elements equals its length.
223. Count Subarrays where the sum of its elements equals `K` times its length.
224. Find Longest Subarray where the sum of its elements equals `K` times its length.
225. Count Subarrays where all elements are positive and their average is greater than `X`.
226. Count Subarrays where all elements are negative and their average is less than `X`.
227. Find Longest Subarray where all elements are positive and their average is greater than `X`.
228. Find Longest Subarray where all elements are negative and their average is less than `X`.
229. Count Subsequences whose elements form a strictly increasing sequence with a common
difference `D`.
230. Find Longest Subsequence whose elements form a strictly increasing sequence with a
common difference `D`.
231. Count Subsequences whose elements form a strictly decreasing sequence with a common
difference `D`.
232. Find Longest Subsequence whose elements form a strictly decreasing sequence with a
common difference `D`.
233. Count Subsequences where all elements are distinct and positive.
234. Find Longest Subsequence where all elements are distinct and positive.
235. Count Subsequences where all elements are distinct and negative.
236. Find Longest Subsequence where all elements are distinct and negative.
237. Count Subsequences where `max(element) - min(element)` is minimized.
238. Find Longest Subsequence where `max(element) - min(element)` is minimized.
239. Count Subsequences where `max(element) - min(element)` is maximized.
240. Find Longest Subsequence where `max(element) - min(element)` is maximized.
241. Count Subarrays with Alternating Parity and Fixed Length `K`.
242. Count Subarrays with Alternating Signs and Fixed Length `K`.
243. Find Longest Subarray with Alternating Parity and Fixed Length `K`.
244. Find Longest Subarray with Alternating Signs and Fixed Length `K`.
245. Count Subarrays where the elements are unique and form a set with `K` distinct numbers.
246. Find Longest Subarray where the elements are unique and form a set with `K` distinct
numbers.
247. Count Subarrays where `max(element) == K`.
248. Count Subarrays where `min(element) == K`.
249. Find Longest Subarray where `max(element) == K`.
250. Find Longest Subarray where `min(element) == K`.
251. Count Subarrays where the sum of elements is less than or equal to `K` using a two-pointer
approach.
252. Count Subarrays where the sum of elements is greater than or equal to `K` using a two-
pointer approach.
253. Count Subarrays where the product of elements is less than or equal to `K` using a two-
pointer approach.
254. Count Subarrays where the product of elements is greater than or equal to `K` using a two-
pointer approach.
255. Count Subarrays where the XOR sum of elements is less than or equal to `K` using a two-
pointer approach.
256. Count Subarrays where the XOR sum of elements is greater than or equal to `K` using a two-
pointer approach.
257. Count Subarrays containing at least `K` prime numbers.
258. Find Longest Subarray containing at least `K` prime numbers.
259. Count Subarrays containing exactly `K` prime numbers.
260. Find Longest Subarray containing exactly `K` prime numbers.
261. Count Subarrays whose elements are all distinct and sum to `S`.
262. Find Longest Subarray whose elements are all distinct and sum to `S`.
263. Count Subarrays whose elements are all positive and sum to `S`.
264. Find Longest Subarray whose elements are all positive and sum to `S`.
265. Count Subarrays whose elements are all negative and sum to `S`.
266. Find Longest Subarray whose elements are all negative and sum to `S`.
267. Count Subarrays whose elements' product is a multiple of `K`.
268. Find Longest Subarray whose elements' product is a multiple of `K`.
269. Count Subarrays whose elements' product is a factor of `K`.
270. Find Longest Subarray whose elements' product is a factor of `K`.
271. Count Subarrays whose elements' XOR sum is a multiple of `K`.
272. Find Longest Subarray whose elements' XOR sum is a multiple of `K`.
273. Count Subarrays where the number of even elements is greater than the number of odd
elements.
274. Count Subarrays where the number of odd elements is greater than the number of even
elements.
275. Find Longest Subarray where the number of even elements is greater than the number of
odd elements.
276. Find Longest Subarray where the number of odd elements is greater than the number of
even elements.
277. Count Subarrays whose elements form a strictly increasing sequence.
278. Count Subarrays whose elements form a strictly decreasing sequence.
279. Find Longest Subarray whose elements form a strictly increasing sequence.
280. Find Longest Subarray whose elements form a strictly decreasing sequence.
281. Count Subarrays whose elements form a non-decreasing sequence.
282. Count Subarrays whose elements form a non-increasing sequence.
283. Find Longest Subarray whose elements form a non-decreasing sequence.
284. Find Longest Subarray whose elements form a non-increasing sequence.
285. Count Subarrays where `max(window) - min(window)` is at most `X` (Two-pointer
approach).
286. Count Subarrays where `max(window) - min(window)` is at least `X` (Two-pointer approach).
287. Find Longest Subarray where `max(window) - min(window)` is at most `X` (Two-pointer
approach).
288. Find Longest Subarray where `max(window) - min(window)` is at least `X` (Two-pointer
approach).
289. Count Subarrays where the sum of elements is a power of 2.
290. Find Longest Subarray where the sum of elements is a power of 2.
291. Count Subarrays where the sum of elements is a perfect square.
292. Find Longest Subarray where the sum of elements is a perfect square.
293. Count Subarrays where elements are distinct and form an arithmetic progression.
294. Find Longest Subarray where elements are distinct and form an arithmetic progression.
295. Count Subarrays where elements are distinct and form a geometric progression.
296. Find Longest Subarray where elements are distinct and form a geometric progression.
297. Count Subarrays containing at least one positive and one negative element.
298. Find Longest Subarray containing at least one positive and one negative element.
299. Count Subarrays where the sum of elements is equal to `K` and all elements are odd.
300. Find Longest Subarray where the sum of elements is equal to `K` and all elements are odd.

#### 5. Kadane’s Algorithm (Max Subarray Sum) (Approx. 300 Problems)

**Core Kadane's & Immediate Extensions:**


1. Maximize Contiguous Subarray Sum.
2. Minimize Contiguous Subarray Sum.
3. Maximize Contiguous Subarray Product.
4. Minimize Contiguous Subarray Product.
5. Maximize Circular Subarray Sum.
6. Minimize Circular Subarray Sum.
7. Maximize Contiguous Subarray Sum with One Element Deletion.
8. Minimize Contiguous Subarray Sum with One Element Deletion.
9. Maximize Contiguous Subarray Sum with At Most K Element Deletions.
10. Minimize Contiguous Subarray Sum with At Most K Element Deletions.
11. Maximize Contiguous Subarray Product with At Most K Element Deletions.
12. Minimize Contiguous Subarray Product with At Most K Element Deletions.
13. Find Start and End Indices of Maximum Sum Subarray.
14. Find Start and End Indices of Minimum Sum Subarray.
15. Find Start and End Indices of Maximum Product Subarray.
16. Find Start and End Indices of Minimum Product Subarray.
17. Count Subarrays with Maximum Sum Equal to X.
18. Count Subarrays with Minimum Sum Equal to X.
19. Count Subarrays with Maximum Product Equal to X.
20. Count Subarrays with Minimum Product Equal to X.
21. Maximize Subarray Sum with Fixed Size K.
22. Minimize Subarray Sum with Fixed Size K.
23. Maximize Subarray Product with Fixed Size K.
24. Minimize Subarray Product with Fixed Size K.
25. Maximize Average Subarray with Fixed Size K.
26. Minimize Average Subarray with Fixed Size K.
27. Maximize Subarray Sum with At Least K Length.
28. Minimize Subarray Sum with At Least K Length.
29. Maximize Subarray Sum with At Most K Length.
30. Minimize Subarray Sum with At Most K Length.
31. Maximize Subarray Sum with Exactly K Length.
32. Minimize Subarray Sum with Exactly K Length.
33. Maximize Subarray Sum Ending at Each Index.
34. Minimize Subarray Sum Ending at Each Index.
35. Maximize Subarray Sum Starting at Each Index.
36. Minimize Subarray Sum Starting at Each Index.
37. Maximize Contiguous Subarray Sum of Length L, ending at index i.
38. Minimize Contiguous Subarray Sum of Length L, ending at index i.
39. Maximize Contiguous Subarray Sum of Length L, starting at index i.
40. Minimize Contiguous Subarray Sum of Length L, starting at index i.

**Constraints & Special Conditions for Kadane's:**


41. Maximize Subarray Sum (All Elements Positive).
42. Minimize Subarray Sum (All Elements Positive).
43. Maximize Subarray Sum (All Elements Negative).
44. Minimize Subarray Sum (All Elements Negative).
45. Maximize Subarray Sum (Bounded by Max Value M).
46. Minimize Subarray Sum (Bounded by Min Value M).
47. Maximize Subarray Sum (Only Even Numbers Allowed).
48. Minimize Subarray Sum (Only Even Numbers Allowed).
49. Maximize Subarray Sum (Only Odd Numbers Allowed).
50. Minimize Subarray Sum (Only Odd Numbers Allowed).
51. Maximize Subarray Sum (Strictly Increasing Elements).
52. Minimize Subarray Sum (Strictly Increasing Elements).
53. Maximize Subarray Sum (Strictly Decreasing Elements).
54. Minimize Subarray Sum (Strictly Decreasing Elements).
55. Maximize Subarray Sum (Alternating Parity).
56. Minimize Subarray Sum (Alternating Parity).
57. Maximize Subarray Sum (Alternating Signs).
58. Minimize Subarray Sum (Alternating Signs).
59. Maximize Subarray Sum (All Unique Elements).
60. Maximize Subarray Sum (No Two Adjacent Elements are Same).
61. Maximize Subarray Sum (Each Element Appears At Most K Times).
62. Maximize Subarray Sum (All Elements are Prime).
63. Maximize Subarray Sum (All Elements are Fibonacci Numbers).
64. Maximize Subarray Sum (Ends with a Specific Value X).
65. Maximize Subarray Sum (Starts with a Specific Value X).
66. Maximize Subarray Sum (Contains a Specific Value X).
67. Maximize Subarray Sum (Does NOT Contain a Specific Value X).
68. Maximize Subarray Sum (All Elements in a Given Range `[Min, Max]`).
69. Maximize Subarray Sum (Sum is a Multiple of K).
70. Maximize Subarray Sum (Sum is a Prime Number).
71. Maximize Subarray Sum (Sum is a Perfect Square).
72. Minimize Subarray Sum (Sum is a Multiple of K).
73. Minimize Subarray Sum (Sum is a Prime Number).
74. Minimize Subarray Sum (Sum is a Perfect Square).
75. Maximize Subarray Sum (Length is a Prime Number).
76. Minimize Subarray Sum (Length is a Prime Number).
77. Maximize Subarray Sum (Length is a Fibonacci Number).
78. Minimize Subarray Sum (Length is a Fibonacci Number).
79. Maximize Subarray Sum (All Elements are Distinct Primes).
80. Maximize Subarray Sum (All Elements are Distinct Squares).

**Combinations & Advanced Kadane's Applications:**


81. Maximize Sum of Two Non-Overlapping Subarrays (Fixed Lengths L and M).
82. Maximize Sum of Three Non-Overlapping Subarrays (Fixed Lengths L, M, N).
83. Maximize Sum of K Non-Overlapping Subarrays (Fixed Lengths).
84. Maximize Sum of Two Overlapping Subarrays (Max of first + Max of second, can be Kadane-
like).
85. Maximize Subarray XOR Sum.
86. Minimize Subarray XOR Sum.
87. Maximize Subarray Bitwise AND Sum.
88. Minimize Subarray Bitwise AND Sum.
89. Maximize Subarray Bitwise OR Sum.
90. Minimize Subarray Bitwise OR Sum.
91. Maximize Subarray Sum Modulo M (Prefix Sums + Kadane-like logic).
92. Minimize Subarray Sum Modulo M (Prefix Sums + Kadane-like logic).
93. Maximize Subarray Sum Closest to Target K (but not exceeding K).
94. Minimize Subarray Sum Closest to Target K (but not less than K).
95. Maximize Subarray Sum with Exactly K Distinct Elements.
96. Minimize Subarray Sum with Exactly K Distinct Elements.
97. Maximize Subarray Sum with At Most K Distinct Elements.
98. Minimize Subarray Sum with At Most K Distinct Elements.
99. Maximize Subarray Sum where elements are selected from K lists.
100. Maximize Score From Removing Stones (from ends, Kadane's idea combined).
101. Maximize Value of an Equation (Points in 2D plane, Kadane's with slope).
102. Largest Sum of Averages (Partition into K subarrays, DP with Kadane's-like structure).
103. Maximum Sum Path in a Binary Tree (Kadane's applied to tree paths).
104. Maximum Sum of a Path in a Directed Acyclic Graph (Kadane's applied to graph paths).
105. Maximum Sum Path in a 2D Grid.
106. Maximum Value of `Array[i] - Array[j]` for `i < j`.
107. Maximum Value of `Array[i] + Array[j]` for `i < j`.
108. Maximum Value of `Array[i] * Array[j]` for `i < j`.
109. Maximum Value of `Array[i] / Array[j]` for `i < j`.
110. Maximum Subarray Sum where Sum is Bounded by X (use two pointers on prefix sums).
111. Maximum Subarray Sum in a 2D Matrix (using 1D Kadane's).
112. Maximum Square Submatrix Sum.
113. Maximum Rectangular Submatrix Sum with a constraint on width/height.
114. Maximum Rectangular Submatrix Sum with a constraint on aspect ratio.
115. Maximum Sum After At Most K Operations (specific operation).
116. Maximum Sum After Partitioning into K Subarrays.
117. Maximum Sum with Element At Most K Times.
118. Maximum Sum with Elements whose Difference is Less Than K.
119. Maximum Sum with Elements that are Consecutive in Value.
120. Maximum Sum of a Subarray where `count(1) == count(0)`.
121. Maximum Sum of a Subarray where `count(1) == count(0)` and `count(2) == count(0)`.
122. Maximum Sum of a "Good" Subarray (definition dependent).
123. Maximum Value of `f(i, j) = (j - i) * min(A[i...j])`.
124. Maximum Value of `f(i, j) = (j - i) * max(A[i...j])`.
125. Maximum Sum of `A[i] + B[j]` for `i < j` from two arrays.
126. Maximum Product of `A[i] * B[j]` for `i < j` from two arrays.
127. Maximum Sum of `A[i] + B[j] + C[k]` for `i < j < k` from three arrays.
128. Maximum Product of `A[i] * B[j] * C[k]` for `i < j < k` from three arrays.
129. Maximum Contiguous Subarray Sum of Length L (using sliding window).
130. Maximum Contiguous Subarray Product of Length L (using sliding window).
131. Maximum Contiguous Subarray Sum after applying K operations (each operation affects a
contiguous subarray).
132. Maximum Sum of Elements in a Subarray where elements are sorted.
133. Maximum Sum of `A[i] + A[j]` such that `A[i] % K == A[j] % K`.
134. Maximum Sum of `A[i] + A[j]` such that `A[i]` and `A[j]` have different parities.
135. Maximum Sum of `A[i] + A[j]` such that `A[i]` and `A[j]` have same parities.
136. Maximum Sum of a Subarray in a Binary Array where the number of ones is `X` times the
number of zeroes.
137. Maximum Sum of a Subarray where all elements are powers of 2.
138. Maximum Sum of a Subarray where all elements are primes.
139. Maximum Sum of a Subarray whose sum is also a prime number.
140. Maximum Sum of a Subarray whose length is a prime number.
141. Maximum Subarray Sum of indices `i` where `Array[i]` is even.
142. Maximum Subarray Sum of indices `i` where `Array[i]` is odd.
143. Maximum Sum of a Subarray, such that all elements are greater than a threshold `T`.
144. Maximum Sum of a Subarray, such that all elements are less than a threshold `T`.
145. Maximum Sum of a Subarray, with an additional constraint on average value.
146. Maximum Sum of a Subarray, considering its elements' bitwise properties.
147. Maximum Sum of a Subarray, where a specific element must be included.
148. Maximum Sum of a Subarray, where a specific element must *not* be included.
149. Maximum Sum of a Subarray that contains exactly K unique elements, and all elements are
positive.
150. Maximum Sum of a Subarray that contains exactly K unique elements, allowing negative
numbers.
151. Maximum Sum of a Subarray that is also an Arithmetic Progression.
152. Maximum Sum of a Subarray that is also a Geometric Progression.
153. Maximum Sum of a Subarray whose sum is closest to zero.
154. Maximum Sum of a Subarray whose sum is closest to `K`.
155. Maximum Sum of a Subarray that forms a "wave" pattern.
156. Maximum Sum of a Subarray with elements in a given range `[MinV, MaxV]`.
157. Maximum Sum of a Subarray where sum of elements equals sum of indices.
158. Maximum Sum of a Subarray where product of elements equals product of indices.
159. Maximum Sum of a Subarray whose elements' difference is maximized.
160. Maximum Sum of a Subarray whose elements' difference is minimized.
161. Maximum Sum of a Subarray with an odd number of positive elements.
162. Maximum Sum of a Subarray with an even number of negative elements.
163. Maximum Sum of a Subarray containing a specific pattern of elements.
164. Maximum Sum of a Subarray where elements are chosen from a specific set.
165. Maximum Sum of a Subarray subject to a sliding window of another array.
166. Maximum Sum of a Subarray where elements must be multiples of K.
167. Maximum Sum of a Subarray where elements must be factors of K.
168. Maximum Sum of a Subarray given that it must contain at least one odd number.
169. Maximum Sum of a Subarray given that it must contain at least one even number.
170. Maximum Sum of a Subarray where the sum of its elements is a perfect square.
171. Maximize `A[i] + A[j] + A[k]` for `i < j < k`.
172. Minimize `A[i] + A[j] + A[k]` for `i < j < k`.
173. Maximize `A[i] * A[j] * A[k]` for `i < j < k`.
174. Minimize `A[i] * A[j] * A[k]` for `i < j < k`.
175. Maximize Sum of `A[i] + A[j] + A[k]` such that `A[i], A[j], A[k]` are distinct.
176. Minimize Sum of `A[i] + A[j] + A[k]` such that `A[i], A[j], A[k]` are distinct.
177. Maximize Sum of `A[i] + A[j] + A[k]` such that `A[i], A[j], A[k]` are even.
178. Minimize Sum of `A[i] + A[j] + A[k]` such that `A[i], A[j], A[k]` are even.
179. Maximize Sum of `A[i] + A[j] + A[k]` such that `A[i], A[j], A[k]` are odd.
180. Minimize Sum of `A[i] + A[j] + A[k]` such that `A[i], A[j], A[k]` are odd.
181. Maximize Sum of `A[i] + A[j] + A[k]` such that sum is divisible by M.
182. Minimize Sum of `A[i] + A[j] + A[k]` such that sum is divisible by M.
183. Maximize Sum of `A[i] + A[j] + A[k]` such that sum is prime.
184. Minimize Sum of `A[i] + A[j] + A[k]` such that sum is prime.
185. Maximize Sum of `A[i] + A[j] + A[k]` such that length of `A[i...k]` is K.
186. Minimize Sum of `A[i] + A[j] + A[k]` such that length of `A[i...k]` is K.
187. Maximize Sum of `A[i] + A[j] + A[k]` from three arrays `X, Y, Z` respectively.
188. Maximize Score by Jumping on Array Elements (DP with Kadane-like transitions).
189. Minimize Cost by Jumping on Array Elements (DP with Kadane-like transitions).
190. Maximize Sum of `A[i] + B[j] + C[k]` from `i, j, k` in a sliding window.
191. Minimize Sum of `A[i] + B[j] + C[k]` from `i, j, k` in a sliding window.
192. Maximize Sum of Subarray with Alternating Signs (can involve Kadane's for two states).
193. Maximize Sum of Subarray with Alternating Parity (can involve Kadane's for two states).
194. Maximize Sum of Subarray with Exactly `K` positive elements.
195. Minimize Sum of Subarray with Exactly `K` positive elements.
196. Maximize Sum of Subarray with At Most `K` positive elements.
197. Minimize Sum of Subarray with At Most `K` positive elements.
198. Maximize Sum of Subarray with At Least `K` positive elements.
199. Minimize Sum of Subarray with At Least `K` positive elements.
200. Maximize Sum of Subarray where elements are from a specific range `[L, R]`.
201. Maximize Sum of Subarray where element `A[i]` is not divisible by `K`.
202. Maximize Sum of Subarray where `A[i]` is divisible by `K`.
203. Maximize Sum of Subarray whose sum is an even number.
204. Maximize Sum of Subarray whose sum is an odd number.
205. Maximize Sum of Subarray whose XOR sum is an even number.
206. Maximize Sum of Subarray whose XOR sum is an odd number.
207. Maximize Sum of Subarray where `max(subarray) - min(subarray) == K`.
208. Maximize Sum of Subarray where `max(subarray) - min(subarray) <= K`.
209. Maximize Sum of Subarray where `max(subarray) - min(subarray) >= K`.
210. Minimize Sum of Subarray where `max(subarray) - min(subarray) == K`.
211. Minimize Sum of Subarray where `max(subarray) - min(subarray) <= K`.
212. Minimize Sum of Subarray where `max(subarray) - min(subarray) >= K`.
213. Maximize Sum of Subarray that forms an arithmetic progression.
214. Maximize Sum of Subarray that forms a geometric progression.
215. Minimize Sum of Subarray that forms an arithmetic progression.
216. Minimize Sum of Subarray that forms a geometric progression.
217. Maximize Sum of Subarray where `A[i] == A[j]` for all `i, j` in subarray.
218. Maximize Sum of Subarray where `A[i] != A[j]` for all `i, j` in subarray.
219. Maximize Sum of Subarray where `count(distinct_elements) == K`.
220. Maximize Sum of Subarray where `count(distinct_elements) <= K`.
221. Maximize Sum of Subarray where `count(distinct_elements) >= K`.
222. Maximize Sum of Subarray whose product is positive.
223. Maximize Sum of Subarray whose product is negative.
224. Maximize Sum of Subarray whose product is zero.
225. Minimize Sum of Subarray whose product is positive.
226. Minimize Sum of Subarray whose product is negative.
227. Minimize Sum of Subarray whose product is zero.
228. Maximize Sum of Subarray where `A[i]` is even and `A[j]` is odd within it.
229. Maximize Sum of Subarray where `A[i]` is odd and `A[j]` is even within it.
230. Maximize Sum of Subarray where `A[i]` and `A[j]` are both prime.
231. Maximize Sum of Subarray where `A[i]` and `A[j]` are both composite.
232. Maximize Sum of Subarray that contains at least one prime.
233. Maximize Sum of Subarray that contains at least one composite.
234. Maximize Sum of Subarray that contains no prime.
235. Maximize Sum of Subarray that contains no composite.
236. Maximize Sum of Subarray such that the sum of elements is equal to the sum of their
indices.
237. Minimize Sum of Subarray such that the sum of elements is equal to the sum of their
indices.
238. Maximize Sum of Subarray where the sum of its elements is a power of K.
239. Minimize Sum of Subarray where the sum of its elements is a power of K.
240. Maximize Sum of Subarray whose length is a power of 2.
241. Minimize Sum of Subarray whose length is a power of 2.
242. Maximize Sum of Subarray whose length is a power of K.
243. Minimize Sum of Subarray whose length is a power of K.
244. Maximize Sum of Subarray where elements are sorted (can be Kadane's on differences).
245. Minimize Sum of Subarray where elements are sorted (can be Kadane's on differences).
246. Maximize Sum of Subarray of Length `L` (using sliding window).
247. Minimize Sum of Subarray of Length `L` (using sliding window).
248. Maximize Sum of Subarray with length in range `[L_min, L_max]`.
249. Minimize Sum of Subarray with length in range `[L_min, L_max]`.
250. Maximize Sum of Subarray such that `A[i]` is a multiple of `i` for all `i` in subarray.
251. Maximize Sum of Subarray such that `A[i]` is a factor of `i` for all `i` in subarray.
252. Maximize Sum of Subarray that contains a specific pattern `[X, Y, Z]`.
253. Minimize Sum of Subarray that contains a specific pattern `[X, Y, Z]`.
254. Maximize Sum of Subarray that begins and ends with the same element.
255. Minimize Sum of Subarray that begins and ends with the same element.
256. Maximize Sum of Subarray containing a fixed value `V` at a fixed index `I`.
257. Minimize Sum of Subarray containing a fixed value `V` at a fixed index `I`.
258. Maximize Sum of Subarray with even length.
259. Maximize Sum of Subarray with odd length.
260. Minimize Sum of Subarray with even length.
261. Minimize Sum of Subarray with odd length.
262. Maximize Sum of Subarray where elements are unique and form an arithmetic progression.
263. Minimize Sum of Subarray where elements are unique and form an arithmetic progression.
264. Maximize Sum of Subarray where elements are unique and form a geometric progression.
265. Minimize Sum of Subarray where elements are unique and form a geometric progression.
266. Maximize Sum of Subarray containing at least `K` unique elements.
267. Minimize Sum of Subarray containing at least `K` unique elements.
268. Maximize Sum of Subarray containing exactly `K` unique elements.
269. Minimize Sum of Subarray containing exactly `K` unique elements.
270. Maximize Sum of Subarray that contains all elements from a given set `S`.
271. Minimize Sum of Subarray that contains all elements from a given set `S`.
272. Maximize Sum of Subarray whose `max(element) - min(element)` is maximized.
273. Minimize Sum of Subarray whose `max(element) - min(element)` is minimized.
274. Maximize Sum of Subarray where `A[i]` and `A[j]` have specific bitwise properties.
275. Minimize Sum of Subarray where `A[i]` and `A[j]` have specific bitwise properties.
276. Maximize Sum of Subarray that has an odd number of odd elements.
277. Maximize Sum of Subarray that has an even number of odd elements.
278. Maximize Sum of Subarray that has an odd number of even elements.
279. Maximize Sum of Subarray that has an even number of even elements.
280. Maximize Sum of Subarray by performing at most `K` operations of incrementing an
element.
281. Maximize Sum of Subarray by performing at most `K` operations of decrementing an
element.
282. Minimize Sum of Subarray by performing at most `K` operations of incrementing an
element.
283. Minimize Sum of Subarray by performing at most `K` operations of decrementing an
element.
284. Maximize Sum of Subarray such that the sum is `X` and length is `Y`.
285. Minimize Sum of Subarray such that the sum is `X` and length is `Y`.
286. Maximize Sum of Subarray where elements appear in increasing frequency.
287. Minimize Sum of Subarray where elements appear in increasing frequency.
288. Maximize Sum of Subarray where elements appear in decreasing frequency.
289. Minimize Sum of Subarray where elements appear in decreasing frequency.
290. Maximize Sum of Subarray containing a specific value `X` exactly `K` times.
291. Minimize Sum of Subarray containing a specific value `X` exactly `K` times.
292. Maximize Sum of Subarray by swapping two elements.
293. Minimize Sum of Subarray by swapping two elements.
294. Maximize Sum of Subarray by reversing a subsegment.
295. Minimize Sum of Subarray by reversing a subsegment.
296. Maximize Sum of Subarray that is also a mountain array.
297. Minimize Sum of Subarray that is also a mountain array.
298. Maximize Sum of Subarray where its elements have a specific sum of digits.
299. Minimize Sum of Subarray where its elements have a specific sum of digits.
300. Maximize Sum of Subarray where it is a subsequence of another given array.

#### 6. Two Pointers Technique (Approx. 300 Problems)

**Basic Two-Pointers (Linear Array, Sorted or Partitioned):**


1. Find Two Elements Summing to Target in Sorted Array.
2. Count Pairs Summing to Target in Sorted Array.
3. Find Two Elements Summing to Target with Maximize Product.
4. Find Two Elements Summing to Target with Minimize Product.
5. Find All Triplets Summing to Zero.
6. Find All Triplets Summing to Target.
7. Find Triplets Summing Closest to Target.
8. Find All Quadruplets Summing to Target.
9. Remove Duplicates from Sorted Array (Unique Elements In-place).
10. Remove Duplicates from Sorted Array (Max Two Occurrences In-place).
11. Remove Specific Value from Array In-place.
12. Move All Zeroes to End of Array (Preserve Order).
13. Move All Target Values to End of Array (Preserve Order).
14. Calculate Max Water Contained Between Vertical Lines.
15. Calculate Total Rainwater Trapped Between Bars.
16. Sort Array of Three Distinct Values (0s, 1s, 2s) In-place.
17. Validate Palindromic String (Alphanumeric, Case-Insensitive).
18. Validate Palindromic String (One Character Deletion Allowed).
19. Reverse String In-place.
20. Reverse Only Vowels in a String.
21. Merge Two Sorted Arrays into First Array (In-place).
22. Generate Sorted Squares of Array from Sorted Input (Two Pointers).
23. Find Longest Palindromic Substring (Expand Around Center).
24. Partition String into Max Parts (Based on Last Seen Character).
25. Find Max Pair Sum Less Than Target K (Sorted Array).
26. Count K-Difference Pairs (Sorted Array).
27. Check if String S1 is a Subsequence of String S2.
28. Compare Two Strings After Backspace Processing.
29. Determine Minimum Length String After Deleting Similar Ends.
30. Find Two Elements Summing to Target in BST (Iterative traversal + Two Pointers).

**Two-Pointers with Additional Constraints/Objectives:**


31. Count Pairs with Sum Equal to K.
32. Count Pairs with Sum Less Than K.
33. Count Pairs with Sum Greater Than K.
34. Count Pairs with Difference Equal to K.
35. Count Pairs with Difference Less Than K.
36. Count Pairs with Difference Greater Than K.
37. Find Maximum Distance Between Two Indices `i, j` with `Array[i] <= Array[j]`.
38. Find Minimum Distance Between Two Indices `i, j` with `Array[i] <= Array[j]`.
39. Find Smallest K Elements (using two-pointer partitioning).
40. Find Largest K Elements (using two-pointer partitioning).
41. Sort Array by Parity (Even First, In-place).
42. Sort Array by Parity (Alternating Parity, In-place).
43. Partition Array into Positive/Negative (Positive First, In-place).
44. Partition Array into Positive/Negative (Negative First, In-place).
45. Find Missing Number (Cyclic Sort + Two Pointers for Swaps).
46. Find Duplicate Number (Floyd's Cycle Detection on Array).
47. Find All Duplicates (Cyclic Sort + Two Pointers for Swaps).
48. Find Corrupt Pair (Missing and Duplicate) Using Cyclic Sort.
49. Find Equilibrium Point (Two Pointers Converging).
50. Maximize `Array[i] + Array[j] + Array[k]` for `i < j < k`.
51. Minimize `Array[i] + Array[j] + Array[k]` for `i < j < k`.
52. Maximize `Array[i] * Array[j] * Array[k]` for `i < j < k`.
53. Minimize `Array[i] * Array[j] * Array[k]` for `i < j < k`.
54. Search Target in Rotated Sorted Array.
55. Search Target in Rotated Sorted Array with Duplicates.
56. Find First and Last Position of Element in Sorted Array (Binary Search + Two Pointers).
57. Find Insertion Point for Element in Sorted Array (Binary Search + Two Pointers).
58. Compute Next Lexicographical Permutation (Two Pointers for pivots/swaps).
59. Remove Adjacent Duplicates in String (Two Pointers).
60. Count Pairs `(i, j)` with `i < j` such that `Array[i] + Array[j]` is divisible by K.
61. Count Triplets `(i, j, k)` with `i < j < k` such that `Array[i] + Array[j] + Array[k]` is divisible by K.
62. Find Max Number of K-Sum Pairs.
63. Maximize Score by Removing Stones from Ends (Two Pointers on sum of remaining).
64. Count Number of Teams (Strictly increasing/decreasing triplets).
65. Smallest Subarray with Sum Greater Than or Equal to Target (Sliding Window + Two
Pointers).
66. Longest Subarray with At Most Two Distinct Elements (Sliding Window + Two Pointers).
67. Count Pairs with Difference K (Two Pointers, handles unsorted if pre-sorted).
68. Maximize `Array[i] XOR Array[j]` (Two Pointers on sorted XORed array, or Trie).
69. Find the Kth Missing Positive Integer (Two Pointers or Cyclic Sort).
70. Minimize Array Length After Deleting Consecutive Similar Elements.
71. Count Subarrays Where Maximum Element is at Least K (Two Pointers).
72. Count Subarrays Where Minimum Element is at Most K (Two Pointers).
73. Calculate Product of Elements in Each Subarray of Length K (Sliding Window + Two
Pointers).
74. Count Subarrays with Odd Sum (Two Pointers on prefix sums).
75. Count Subarrays with Even Sum (Two Pointers on prefix sums).
76. Find the Longest Subarray with Each Element Unique (Two Pointers + Hash Set).
77. Maximize Sum of Two Non-Overlapping Subarrays (fixed length, two pointers on prefix
sums).
78. Maximize Sum of Two Non-Overlapping Subarrays (variable length, two pointers on prefix
sums).
79. Find the Shortest Unsorted Continuous Subarray (Two Pointers).
80. Check if Array Can Be Sorted by Reversing One Subarray (Two Pointers).

**Two-Pointers for String/Character Arrays:**


81. Find Longest Palindromic Substring (Expand Around Center).
82. Remove All Adjacent Duplicates in String (Two Pointers).
83. Longest Substring Without 3 Consecutive Identical Characters (Two Pointers).
84. Reverse Words in a String (Two Pointers for word boundaries).
85. Reverse Characters of Each Word in a String (Two Pointers for each word).
86. Check if String Can Form a Palindrome (Frequency check with Two Pointers).
87. Find All Anagrams in a String (Sliding Window + Two Pointers).
88. Permutation in String (Sliding Window + Two Pointers).
89. Minimum Window Substring (Sliding Window + Two Pointers).
90. Longest Substring With At Most K Distinct Characters (Sliding Window + Two Pointers).
91. Longest Substring With Exactly K Distinct Characters (Sliding Window + Two Pointers).
92. Smallest Window Containing All Characters of Another String (Sliding Window + Two
Pointers).
93. Count Subarrays of Characters with K Distinct Elements (Sliding Window + Two Pointers).
94. Max Consecutive Ones III (with K flips, Binary Array) (Sliding Window + Two Pointers).
95. Number of Substrings Containing All Three Required Characters (Sliding Window + Two
Pointers).
96. Longest Repeating Character Replacement (Sliding Window + Two Pointers).
97. Fruit Into Baskets (Sliding Window + Two Pointers).
98. Longest Nice Substring (Sliding Window + Two Pointers).
99. Count Homogeneous Substrings (Two Pointers).
100. Max Vowels in Substring of Fixed Length (Sliding Window + Two Pointers).

**Two-Pointers with Monotonicity/Order:**


101. Find First Element Greater Than Target in Sorted Array.
102. Find Last Element Less Than Target in Sorted Array.
103. Find Element Equal to Its Index (Sorted Array, Two Pointers).
104. Find All Elements Equal to Their Indices (Sorted Array, Two Pointers).
105. Find Longest Subarray Where Max Element is K (Two Pointers).
106. Find Longest Subarray Where Min Element is K (Two Pointers).
107. Count Elements Smaller Than Current Element to Its Right (Merge Sort Two Pointers).
108. Count Elements Greater Than Current Element to Its Right (Merge Sort Two Pointers).
109. Count Inversions in an Array (Merge Sort Two Pointers).
110. Find Kth Smallest Element in Two Sorted Arrays (Two Pointers).
111. Find Kth Largest Element in Two Sorted Arrays (Two Pointers).
112. Find Median of Two Sorted Arrays (Two Pointers).
113. Find Pivot Point in Rotated Sorted Array (Binary Search + Two Pointers).
114. Find Two Elements in Sorted Rotated Array with Target Sum (Two Pointers).
115. Count Pairs with Absolute Difference K (Two Pointers on sorted array).
116. Count Pairs with Sum K in Sorted Rotated Array (Two Pointers).
117. Three Sum with Multiplicity (Two Pointers after sorting).
118. Four Sum with Multiplicity (Two Pointers + Hash Map).
119. Find Longest Subarray with Bounded Difference (Two Pointers + Min/Max Deques).
120. Find Longest Subarray with at most K distinct elements (Two Pointers + Hash Map).
121. Find Longest Subarray with exactly K distinct elements (Two Pointers + Hash Map).
122. Find Longest Subarray with sum `K` (Two Pointers + Prefix Sums/Hash Map).
123. Find Smallest Subarray with sum `K` (Two Pointers + Prefix Sums/Hash Map).
124. Count Subarrays with Product Less Than K (Two Pointers).
125. Count Subarrays with XOR Sum K (Two Pointers + Hash Map).
126. Find Maximum Difference Between Increasing Elements (One Pass, Two Pointers).
127. Count Triplets `(i, j, k)` such that `Array[i] < Array[j] < Array[k]` (Two Pointers).
128. Count Triplets `(i, j, k)` such that `Array[i] > Array[j] > Array[k]` (Two Pointers).
129. Find Longest Sequence of Consecutive Elements (Two Pointers + Hash Set).
130. Minimize Max Pair Sum in an Array (Two Pointers).
131. Maximize Score from Removing Stones (Two Pointers from ends).
132. Smallest Range Covering Elements from K Sorted Lists (Two Pointers + Min Heap).
133. Find Max Number of K-Sum Pairs (Two Pointers after sorting).
134. Two Sum II - Input Array Is Sorted (Simple Two Pointers).
135. Array Partition I (Maximize sum of `min(ai, bi)` by sorting and two pointers).
136. Sort Array By Parity II (Alternating even/odd, Two Pointers).
137. Find all Duplicates in an Array (Two Pointers, in-place modification).
138. Find Duplicate and Missing Number (Two Pointers for cycle detection).
139. Minimum Deletions to Make Array Sorted (Longest increasing subsequence with two
pointers for verification).
140. Check if Array Forms a Valid Mountain (Two Pointers).
141. Find Pivot Index (Two Pointers to calculate prefix/suffix sums).
142. Replace Elements with Greatest Element on Right Side (Two Pointers from right).
143. Count Good Triplets (Two Pointers on subproblems).
144. Number of Subsequences with Sum Less Than or Equal to Target (Two Pointers with binary
search or recursion).
145. Count Pairs whose Sum is a Power of Two (Two Pointers + Bit Manipulation).
146. Count Quadruplets that Sum to a Target Value (Two Pointers + Hash Map).
147. Find Max XOR of Two Numbers in an Array (Trie + Two Pointers for traversal).
148. Find Kth Smallest Element in an Unsorted Array (Quickselect + Two Pointers for partition).
149. Find Kth Largest Element in an Unsorted Array (Quickselect + Two Pointers for partition).
150. Maximize Sum of `A[i] * i` over all Rotations of an Array (Two Pointers for rotating sums).
151. Minimize Sum of `A[i] * i` over all Rotations of an Array (Two Pointers for rotating sums).
152. Generate All Combinations for a Sum (with repetition, Two Pointers/Backtracking).
153. Generate All Combinations for a Sum (without repetition, Two Pointers/Backtracking).
154. Count Distinct Subsequences (Two Pointers with DP).
155. Count Distinct Palindromic Subsequences (Two Pointers with DP).
156. Find the Minimum Number of Operations to Make Array Sorted (Two Pointers for
comparing).
157. Find the Maximum Sum of a Valid Split of an Array (Two Pointers for split point).
158. Count Subarrays that Contain at Least One K (Two Pointers).
159. Find the Number of Times a Value K Appears in All Subarrays (Two Pointers for window).
160. Find the Maximum Length Subarray with a Specific XOR Value (Two Pointers + Hash Map).
161. Find the Smallest Missing Positive Integer (Cyclic Sort + Two Pointers).
162. Find all Duplicate Numbers (Cyclic Sort + Two Pointers).
163. Find the First Missing Positive Integer (Cyclic Sort + Two Pointers).
164. Count Pairs `(i, j)` where `A[i] + A[j]` is a prime number (Two Pointers after sorting).
165. Count Pairs `(i, j)` where `A[i] + A[j]` is a perfect square (Two Pointers after sorting).
166. Count Pairs `(i, j)` where `A[i] + A[j]` is a power of two (Two Pointers after sorting).
167. Find Max Sum Subarray with Given Length L and value V at end (Two Pointers for window).
168. Find Min Sum Subarray with Given Length L and value V at end (Two Pointers for window).
169. Find Max Product Subarray with Given Length L and value V at end (Two Pointers for
window).
170. Find Min Product Subarray with Given Length L and value V at end (Two Pointers for
window).
171. Find Longest Subarray of Consecutive Elements (Sorted Array, Two Pointers).
172. Find Longest Subarray of Alternating Elements (Sorted Array, Two Pointers).
173. Count Ways to Form Target Sum Using Two Numbers (Two Pointers).
174. Count Ways to Form Target Sum Using Three Numbers (Two Pointers).
175. Count Ways to Form Target Sum Using Four Numbers (Two Pointers).
176. Maximize Sum of `A[i] + A[j]` where `A[i]` is even and `A[j]` is odd (Two Pointers for
partitions).
177. Maximize Sum of `A[i] + A[j]` where `A[i]` is odd and `A[j]` is even (Two Pointers for
partitions).
178. Find Longest Subarray where Sum of Elements Equals Sum of Indices (Two Pointers + Hash
Map).
179. Find Smallest Subarray where Sum of Elements Equals Sum of Indices (Two Pointers +
Hash Map).
180. Count Pairs `(i, j)` with `i < j` and `(A[i] + A[j])` is divisible by `K` (Two Pointers + Modulo
Hash).
181. Count Triplets `(i, j, k)` with `i < j < k` and `(A[i] + A[j] + A[k])` is divisible by `K` (Two Pointers +
Modulo Hash).
182. Find Max Value of `A[i] * i` after any number of rotations (Two Pointers on rotating array).
183. Find Min Value of `A[i] * i` after any number of rotations (Two Pointers on rotating array).
184. Count Subarrays where elements are sorted (Two Pointers for start/end of sorted
segments).
185. Find Longest Subarray where elements are sorted (Two Pointers for start/end of sorted
segments).
186. Count Subarrays whose elements are all distinct (Two Pointers + Hash Set).
187. Find Longest Subarray whose elements are all distinct (Two Pointers + Hash Set).
188. Find Minimum Number of Swaps to Sort an Array (Cycle Sort or Two Pointers for swaps).
189. Count Pairs `(i, j)` with `i < j` and `A[i]` and `A[j]` are coprime (Two Pointers with number
theory).
190. Count Pairs `(i, j)` with `i < j` and `A[i]` and `A[j]` share a common factor (Two Pointers).
191. Find Longest Subarray whose elements are prime numbers (Two Pointers + Sieve).
192. Count Pairs `(i, j)` with `i < j` such that `A[i] == A[j] + K` (Two Pointers).
193. Count Pairs `(i, j)` with `i < j` such that `A[i] == A[j] - K` (Two Pointers).
194. Find Max Sum Subarray that contains at least one prime number (Two Pointers).
195. Find Min Sum Subarray that contains at least one prime number (Two Pointers).
196. Find Max Sum Subarray that contains no prime numbers (Two Pointers).
197. Find Min Sum Subarray that contains no prime numbers (Two Pointers).
198. Count Subarrays with Sum `K` and all elements are distinct (Two Pointers).
199. Count Subarrays with Sum `K` and all elements are positive (Two Pointers).
200. Count Subarrays with Sum `K` and all elements are negative (Two Pointers).
201. Find Max Sum of Two Non-Overlapping Subarrays of Variable Lengths (DP + Two Pointers).
202. Find Min Sum of Two Non-Overlapping Subarrays of Variable Lengths (DP + Two Pointers).
203. Find Longest Subarray such that all elements are even or all elements are odd (Two
Pointers).
204. Count Subarrays such that all elements are even or all elements are odd (Two Pointers).
205. Find Kth Smallest Element in an Array where duplicates count (Two Pointers + Counting).
206. Find Kth Largest Element in an Array where duplicates count (Two Pointers + Counting).
207. Find Smallest Window in a Circular Array that sums to K (Two Pointers with circular logic).
208. Find Smallest Window in a Circular Array that contains K distinct elements (Two Pointers +
Circular Hash).
209. Count Pairs `(i, j)` with `i < j` such that `A[i] + A[j]` is less than `K` (Two Pointers).
210. Count Pairs `(i, j)` with `i < j` such that `A[i] + A[j]` is greater than `K` (Two Pointers).
211. Count Triplets `(i, j, k)` with `i < j < k` such that `A[i] + A[j] + A[k]` is less than `K` (Two
Pointers).
212. Count Triplets `(i, j, k)` with `i < j < k` such that `A[i] + A[j] + A[k]` is greater than `K` (Two
Pointers).
213. Find all Pairs `(i, j)` such that `A[i]` and `A[j]` are consecutive numbers (Two Pointers).
214. Find Longest Subarray where `A[i] == A[i+1]` or `A[i] == A[i+1] + 1` (Two Pointers).
215. Count Subarrays which are Bitonic (Two Pointers).
216. Find Longest Bitonic Subarray (Two Pointers).
217. Find Max Score by Removing K Elements from Any Position (Two Pointers + Data
Structure).
218. Find Min Score by Removing K Elements from Any Position (Two Pointers + Data Structure).
219. Maximize Sum of `A[i] + A[j]` where `A[i]` and `A[j]` have specific bitwise properties.
220. Maximize Sum of `A[i] + A[j]` where `A[i]` and `A[j]` are both powers of 2.
221. Minimize Sum of `A[i] + A[j]` where `A[i]` and `A[j]` are both powers of 2.
222. Maximize Sum of `A[i] + A[j]` where `A[i]` is prime and `A[j]` is composite.
223. Minimize Sum of `A[i] + A[j]` where `A[i]` is prime and `A[j]` is composite.
224. Maximize Sum of `A[i] + A[j]` where `A[i]` and `A[j]` are from different halves of the array.
225. Maximize Sum of `A[i] + A[j]` where `A[i]` and `A[j]` are from the same half of the array.
226. Count pairs `(i, j)` where `A[i]` and `A[j]` have different signs (Two Pointers).
227. Count pairs `(i, j)` where `A[i]` and `A[j]` have the same sign (Two Pointers).
228. Find Longest Subarray of elements with same sign (Two Pointers).
229. Find Longest Subarray of elements with different signs (Two Pointers).
230. Count Subarrays where elements are sorted in ascending order (Two Pointers).
231. Count Subarrays where elements are sorted in descending order (Two Pointers).
232. Find Longest Subarray where elements are sorted in ascending order (Two Pointers).
233. Find Longest Subarray where elements are sorted in descending order (Two Pointers).
234. Find the number of pairs `(i, j)` such that `A[i]` is strictly less than `A[j]` and `i < j`.
235. Find the number of pairs `(i, j)` such that `A[i]` is strictly greater than `A[j]` and `i < j`.
236. Find the number of pairs `(i, j)` such that `A[i]` is less than or equal to `A[j]` and `i < j`.
237. Find the number of pairs `(i, j)` such that `A[i]` is greater than or equal to `A[j]` and `i < j`.
238. Find the maximum length of a subarray where `max(element) - min(element)` is at most `K`.
239. Find the maximum length of a subarray where `max(element) - min(element)` is at least `K`.
240. Count subarrays where `max(element) - min(element)` is at most `K`.
241. Count subarrays where `max(element) - min(element)` is at least `K`.
242. Count subarrays where `max(element) - min(element)` is exactly `K`.
243. Find the longest subarray where `max(element) - min(element)` is exactly `K`.
244. Find the number of pairs `(i, j)` such that `A[i] % M == A[j] % M` and `i < j`.
245. Find the number of triplets `(i, j, k)` such that `A[i] % M == A[j] % M == A[k] % M` and `i < j < k`.
246. Maximize `A[i] + A[j]` where `A[i]` is positive and `A[j]` is negative.
247. Maximize `A[i] + A[j]` where `A[i]` is negative and `A[j]` is positive.
248. Minimize `A[i] + A[j]` where `A[i]` is positive and `A[j]` is negative.
249. Minimize `A[i] + A[j]` where `A[i]` is negative and `A[j]` is positive.
250. Maximize `A[i] * A[j]` where `A[i]` is positive and `A[j]` is negative.
251. Maximize `A[i] * A[j]` where `A[i]` is negative and `A[j]` is positive.
252. Minimize `A[i] * A[j]` where `A[i]` is positive and `A[j]` is negative.
253. Minimize `A[i] * A[j]` where `A[i]` is negative and `A[j]` is positive.
254. Count pairs `(i, j)` such that `i < j` and `A[i]` is a factor of `A[j]` (Two Pointers on sorted array).
255. Count pairs `(i, j)` such that `i < j` and `A[j]` is a multiple of `A[i]` (Two Pointers on sorted
array).
256. Find the number of subarrays whose elements, when sorted, form an arithmetic progression
(Two Pointers for checking property).
257. Find the number of subarrays whose elements, when sorted, form a geometric progression
(Two Pointers for checking property).
258. Find the maximum number of pairs `(A[i], A[j])` where `A[i] <= A[j]` (Two Pointers for
counting).
259. Find the minimum number of pairs `(A[i], A[j])` where `A[i] <= A[j]` (Two Pointers for
counting).
260. Count pairs `(i, j)` such that `A[i]` is greater than `K` and `A[j]` is less than `K` (Two Pointers).
261. Count pairs `(i, j)` such that `A[i]` is less than `K` and `A[j]` is greater than `K` (Two Pointers).
262. Find the longest subarray of `0`s and `1`s with equal counts (Two Pointers + Hash Map).
263. Find the longest subarray of `0`s, `1`s, and `2`s with equal counts (Two Pointers + Hash
Map).
264. Count subarrays with equal `0`s and `1`s (Two Pointers + Hash Map).
265. Count subarrays with equal `0`s, `1`s, and `2`s (Two Pointers + Hash Map).
266. Count distinct values in a window of size `K` for each window (Sliding Window + Two
Pointers + Hash Map).
267. Find `k` most frequent elements in an array (Two Pointers + Hash Map + Min Heap).
268. Find `k` least frequent elements in an array (Two Pointers + Hash Map + Max Heap).
269. Maximize the sum of `min(pair)` by partitioning an array into `N/2` pairs.
270. Maximize the number of pairs `(i, j)` such that `A[i] * A[j]` is an even number.
271. Maximize the number of pairs `(i, j)` such that `A[i] * A[j]` is an odd number.
272. Minimize the number of pairs `(i, j)` such that `A[i] * A[j]` is an even number.
273. Minimize the number of pairs `(i, j)` such that `A[i] * A[j]` is an odd number.
274. Count pairs `(i, j)` such that `i < j` and `A[i]` is a prime and `A[j]` is a prime.
275. Count pairs `(i, j)` such that `i < j` and `A[i]` is a composite and `A[j]` is a composite.
276. Count pairs `(i, j)` such that `i < j` and `A[i]` is prime and `A[j]` is composite.
277. Count pairs `(i, j)` such that `i < j` and `A[i]` is composite and `A[j]` is prime.
278. Find the longest subarray where `A[i]` and `A[i+1]` are consecutive numbers (Two Pointers).
279. Find the shortest subarray where `A[i]` and `A[i+1]` are consecutive numbers (Two Pointers).
280. Find the longest subarray where `A[i]` and `A[i+1]` have the same parity (Two Pointers).
281. Find the shortest subarray where `A[i]` and `A[i+1]` have the same parity (Two Pointers).
282. Find the longest subarray where `A[i]` and `A[i+1]` have different parity (Two Pointers).
283. Find the shortest subarray where `A[i]` and `A[i+1]` have different parity (Two Pointers).
284. Count elements that appear in both arrays (Two Pointers on sorted arrays).
285. Count unique elements that appear in both arrays (Two Pointers on sorted arrays).
286. Count elements that appear in first array but not second (Two Pointers on sorted arrays).
287. Count elements that appear in second array but not first (Two Pointers on sorted arrays).
288. Find the intersection of three sorted arrays (Three Pointers).
289. Find the intersection of K sorted arrays (K Pointers or Min Heap).
290. Find the union of three sorted arrays (Three Pointers).
291. Find the union of K sorted arrays (K Pointers or Min Heap).
292. Find the smallest range that covers elements from K sorted lists (Two Pointers + Min Heap).
293. Find the number of subarrays with product `K` (Two Pointers + Logarithms/Hash).
294. Find the longest subarray with product `K` (Two Pointers + Logarithms/Hash).
295. Find the shortest subarray with product `K` (Two Pointers + Logarithms/Hash).
296. Maximize `A[i] + A[j] + A[k]` from `A[i], A[j], A[k]` where `i < j < k`, using two pointers for pairs.
297. Minimize `A[i] + A[j] + A[k]` from `A[i], A[j], A[k]` where `i < j < k`, using two pointers for pairs.
298. Count pairs `(i, j)` such that `A[i]` is an even number and `A[j]` is an odd number, `i < j`.
299. Count pairs `(i, j)` such that `A[i]` is an odd number and `A[j]` is an even number, `i < j`.
300. Maximize score by picking `K` elements, starting from either end (Two pointers, then
choose).

#### 7. Sliding Window Technique (Approx. 300 Problems)

**Fixed-Size Window (Length K):**


1. Maximize Sum of Contiguous Subarray of Fixed Size K.
2. Minimize Sum of Contiguous Subarray of Fixed Size K.
3. Maximize Product of Contiguous Subarray of Fixed Size K.
4. Minimize Product of Contiguous Subarray of Fixed Size K.
5. Maximize Average of Contiguous Subarray of Fixed Size K.
6. Minimize Average of Contiguous Subarray of Fixed Size K.
7. Find First Negative Element in Every Window of Size K.
8. Find Last Negative Element in Every Window of Size K.
9. Count Occurrences of Anagrams of a Pattern (Fixed Window).
10. Find All Starting Indices of Pattern Anagrams (Fixed Window).
11. Count Subarrays with All Positive Elements (Fixed Size K).
12. Count Subarrays with All Negative Elements (Fixed Size K).
13. Count Subarrays with At Least One Zero (Fixed Size K).
14. Count Subarrays with No Zeroes (Fixed Size K).
15. Count Distinct Elements in Every Window of Size K.
16. Maximize Distinct Elements in a Window of Size K.
17. Minimize Distinct Elements in a Window of Size K.
18. Count Subarrays Where Max Element is K (Fixed Size K).
19. Count Subarrays Where Min Element is K (Fixed Size K).
20. Calculate Sum of Elements for Each Window of Size K.
21. Calculate Product of Elements for Each Window of Size K.
22. Calculate XOR Sum of Elements for Each Window of Size K.
23. Find Median of Elements for Each Window of Size K.
24. Calculate Average of Elements for Each Window of Size K.
25. Count Peaks in Each Window of Size K.
26. Count Valleys in Each Window of Size K.
27. Check if Window Contains a Palindrome (Fixed Size K).
28. Check if Window is Sorted (Fixed Size K).
29. Check if Window Contains Consecutive Elements (Fixed Size K).
30. Count Windows with Elements Summing to K.
31. Count Windows with Elements Product K.
32. Count Windows with Elements XOR Sum K.
33. Maximize Subarray Sum from Two Arrays with Fixed Window (Window in each array).
34. Minimize Subarray Sum from Two Arrays with Fixed Window.
35. Maximize Subarray Product from Two Arrays with Fixed Window.
36. Minimize Subarray Product from Two Arrays with Fixed Window.
37. Count Subarrays of Fixed Size K that are Palindromic.
38. Count Subarrays of Fixed Size K that are Sorted.
39. Count Subarrays of Fixed Size K that are Reverse Sorted.
40. Find Longest Subarray of Fixed Size K that is Palindromic.
41. Find Longest Subarray of Fixed Size K that is Sorted.
42. Find Longest Subarray of Fixed Size K that is Reverse Sorted.
43. Maximize Value of `A[i] - A[j]` in a Window of Size K.
44. Minimize Value of `A[i] - A[j]` in a Window of Size K.
45. Maximize Value of `A[i] + A[j]` in a Window of Size K.
46. Minimize Value of `A[i] + A[j]` in a Window of Size K.
47. Count Pairs `(i, j)` in a Window of Size K with Sum S.
48. Count Pairs `(i, j)` in a Window of Size K with Difference D.
49. Find Max Value of Expression `A[i] + B[j] + C[k]` where `i, j, k` are in a sliding window.
50. Find Min Value of Expression `A[i] + B[j] + C[k]` where `i, j, k` are in a sliding window.
51. Count Number of Subarrays which are Arithmetic Progressions within a window.
52. Count Number of Subarrays which are Geometric Progressions within a window.
53. Find the Longest Subarray whose elements' XOR sum is a prime number (Fixed Window).
54. Find the Longest Subarray whose elements' sum is a perfect square (Fixed Window).
55. Find the Smallest Window in a Circular Array with a specific sum (Fixed Window).
56. Find the Smallest Window in a Circular Array with K distinct elements (Fixed Window).
57. Count Distinct Substrings of Length K.
58. Count Distinct Substrings of All Lengths.
59. Maximize Sum of a Subarray of Length K that also contains at least one prime number.
60. Maximize Sum of a Subarray of Length K that contains no duplicate elements.

**Variable-Size Window (Shrinking/Expanding):**


61. Longest Substring Without Repeated Characters.
62. Longest Substring With At Most K Distinct Characters.
63. Longest Substring With Exactly K Distinct Characters.
64. Smallest Window Containing All Characters of Another String.
65. Check If String Contains Permutation of Another String.
66. Smallest Subarray With Sum Greater Than or Equal to Target.
67. Longest Substring With At Least K Repeating Characters.
68. Max Consecutive Ones III (with K flips).
69. Number of Substrings Containing All Three Required Characters.
70. Count Subarrays with K Different Integers.
71. Longest Repeating Character Replacement (with K replacements).
72. Maximum Erasure Value (Max sum unique subarray).
73. Shortest Subarray with Sum At Least K (using deque).
74. Longest Turbulent Subarray.
75. Smallest Window With All Unique Characters.
76. Count Subarrays with Bounded Max-Min Difference (<= K).
77. Count Subarrays with Bounded Max-Min Difference (Exactly K).
78. Longest Subarray with Bounded Max-Min Difference (<= K).
79. Longest Subarray with Bounded Max-Min Difference (Exactly K).
80. Longest Substring With Valid Parentheses (Sliding Window based).
81. Longest Substring With Palindromic Property.
82. Count Substrings that are Palindromic.
83. Count Subarrays where Sum is a Multiple of K.
84. Count Subarrays where Product is Less Than K.
85. Count Subarrays where XOR Sum is K.
86. Smallest Window whose Sum is Exactly K.
87. Smallest Window whose Product is Exactly K.
88. Smallest Window whose XOR Sum is Exactly K.
89. Longest Subarray with Equal Number of 0s and 1s.
90. Longest Subarray with Equal Number of 0s, 1s, and 2s.
91. Longest Subarray with Alternating Even/Odd Elements.
92. Longest Subarray with Alternating Positive/Negative Elements.
93. Maximum Score From Removing Stones (from ends, Sliding Window variant).
94. Minimum Operations to Reduce X to Zero (Sliding Window variant).
95. Grumpy Bookstore Owner (Maximize satisfaction by making happy for K minutes).
96. Max Consecutive Ones II (with one flip).
97. Longest Nice Substring (Sliding Window to check property).
98. Count Number of Homogenous Substrings.
99. Maximum Number of Vowels in a Substring of Given Length.
100. Longest Substring with Each Character Appearing At Most K Times.
101. Longest Substring With Distinct Characters And Bounded Length.
102. Count Subarrays where the number of `1`s is `K` times the number of `0`s.
103. Find the Smallest Window with Maximum Frequency of any element.
104. Find the Smallest Window containing at least one occurrence of all elements in a given set.
105. Longest Substring of a Binary String Containing K Consecutive `1`s.
106. Longest Substring of a Binary String Containing K Consecutive `0`s.
107. Count Substrings Where Every Character Appears At Least K Times.
108. Longest Substring where Every Character Appears At Least K Times.
109. Count Pairs of Elements `(i, j)` within a Window of Size `K` satisfying a condition.
110. Smallest Window to Delete to Make Remaining Array Sorted.
111. Smallest Window to Reverse to Make Entire Array Sorted.
112. Longest Subarray with At Least Two Distinct Elements.
113. Longest Subarray with At Least Three Distinct Elements.
114. Count Subarrays with Sum Less Than or Equal to Target.
115. Count Subarrays with Product Less Than or Equal to Target.
116. Count Subarrays with XOR Sum Less Than or Equal to Target.
117. Count Subarrays with Sum in a Range `[L, R]`.
118. Count Subarrays with Product in a Range `[L, R]`.
119. Count Subarrays with XOR Sum in a Range `[L, R]`.
120. Find Longest Subarray with Sum in a Range `[L, R]`.

**Advanced Sliding Window / Combinations:**


121. Sliding Window Maximum (using Deque).
122. Sliding Window Minimum (using Deque).
123. Sliding Window Average (Efficiently calculate).
124. Sliding Window Sum (Efficiently calculate).
125. Sliding Window Product (Efficiently calculate).
126. Sliding Window XOR Sum (Efficiently calculate).
127. Sliding Window Median (using Two Heaps).
128. Sliding Window with Custom Aggregation Function (e.g., mode).
129. Find Max Value of `f(i, j) = (j - i) * (Sum(i...j))` in a window.
130. Find Max Value of `f(i, j) = (j - i) * min(Array[i...j])` in a window.
131. Find Max Value of `f(i, j) = (j - i) * max(Array[i...j])` in a window.
132. Count Subarrays with Sum Less Than or Equal to K (Optimized).
133. Count Subarrays with Sum Greater Than or Equal to K (Optimized).
134. Count Subarrays with Product Less Than or Equal to K (Optimized).
135. Count Subarrays with Product Greater Than or Equal to K (Optimized).
136. Count Subarrays with XOR Sum Less Than or Equal to K (Optimized).
137. Count Subarrays with XOR Sum Greater Than or Equal to K (Optimized).
138. Max Sum of K-Length Subarrays with Specific Property.
139. Min Sum of K-Length Subarrays with Specific Property.
140. Count Subarrays with Length in Range `[L, R]` and Sum S.
141. Find Longest Subarray with Length in Range `[L, R]` and Sum S.
142. Count Subarrays Where All Elements are Identical (Sliding Window).
143. Count Subarrays Where All Elements are Unique (Sliding Window).
144. Count Inversions within Each Sliding Window.
145. Find Longest Good Subarray (specific sliding window condition).
146. Find Smallest Good Subarray (specific sliding window condition).
147. Maximize Average of a Subarray of Length at Least K.
148. Maximize Average of a Subarray of Length at Most K.
149. Maximize Average of a Subarray of Length Exactly K.
150. Minimize Average of a Subarray of Length at Least K.
151. Minimize Average of a Subarray of Length at Most K.
152. Minimize Average of a Subarray of Length Exactly K.
153. Count Subarrays with an Even Number of Odd Elements.
154. Count Subarrays with an Odd Number of Even Elements.
155. Count Subarrays where the Number of Positive Elements equals Number of Negative
Elements.
156. Find Longest Subarray where the Number of Positive Elements equals Number of Negative
Elements.
157. Sliding Window for Max Score given a sequence of operations over windows.
158. Find the Maximum Number of Items that can be Packed in a Container of Capacity K
(Sliding Window for weight/volume).
159. Count Subarrays of Length K that are Palindromic.
160. Count Subarrays of Length K that are Sorted.
161. Find Longest Subarray of Length K that is Palindromic.
162. Find Longest Subarray of Length K that is Sorted.
163. Maximize Value of `A[i] - A[j]` in a Window of Size K.
164. Minimize Value of `A[i] - A[j]` in a Window of Size K.
165. Maximize Value of `A[i] + A[j]` in a Window of Size K.
166. Minimize Value of `A[i] + A[j]` in a Window of Size K.
167. Count Pairs `(i, j)` in a Window of Size K with Sum S.
168. Count Pairs `(i, j)` in a Window of Size K with Difference D.
169. Find Max Value of Expression `A[i] + B[j] + C[k]` where `i, j, k` are in a sliding window.
170. Find Min Value of Expression `A[i] + B[j] + C[k]` where `i, j, k` are in a sliding window.
171. Count Number of Subarrays which are Arithmetic Progressions within a window.
172. Count Number of Subarrays which are Geometric Progressions within a window.
173. Find the Longest Subarray whose elements' XOR sum is a prime number.
174. Find the Longest Subarray whose elements' sum is a perfect square.
175. Find the Smallest Window in a Circular Array with a specific sum.
176. Find the Smallest Window in a Circular Array with K distinct elements.
177. Count Distinct Substrings of Length K.
178. Count Distinct Substrings of All Lengths.
179. Find Longest Substring which is a concatenation of words from a dictionary.
180. Count Subarrays where all elements are positive, and the sum is less than K.
181. Count Subarrays where all elements are negative, and the sum is greater than K.
182. Maximize Sum of a Subarray of Length K that also contains at least one prime number.
183. Maximize Sum of a Subarray of Length K that contains no duplicate elements.
184. Maximize Sum of a Subarray of Length K such that all its elements are distinct and form a
consecutive sequence.
185. Count Subarrays with a Given Sum in a Circular Array (Sliding Window).
186. Find the Longest Subarray with a Given Sum in a Circular Array (Sliding Window).
187. Count Number of Subarrays whose sum of elements equals sum of indices within the
window.
188. Find Max Score by Removing `K` Elements, where `K` is also variable but within limits.
189. Find the Maximum Number of Nested Subarrays (based on some property).
190. Find the Minimum Number of Nested Subarrays.
191. Count Subarrays that contain both the maximum and minimum elements of the entire array.
192. Find Longest Subarray that contains both the maximum and minimum elements of the
entire array.
193. Count Subarrays where the median element satisfies a given condition.
194. Find the Longest Subarray where the median element satisfies a given condition.
195. Count Subarrays where the number of prime elements is at least K.
196. Count Subarrays where the number of composite elements is at least K.
197. Maximize Number of Employees that can be selected from a list (Sliding Window for time/
location).
198. Count Subarrays of Length K containing a specific element.
199. Find the Smallest Window that contains at least `K` unique elements.
200. Find the Maximum Length of a Subarray such that all its elements have the same sign.
201. Count Subarrays such that all its elements have the same sign.
202. Find the Maximum Length of a Subarray such that all its elements have the same parity.
203. Count Subarrays such that all its elements have the same parity.
204. Find the Longest Subarray where the product of elements is less than `K` and all elements
are positive.
205. Find the Longest Subarray where the product of elements is less than `K` and elements can
be negative.
206. Count Subarrays that form a "zigzag" pattern.
207. Find the Longest Subarray that forms a "zigzag" pattern.
208. Count Subarrays where the sum of `max(window) - min(window)` is at most `X`.
209. Count Subarrays where the average of elements is less than `X`.
210. Count Subarrays where the average of elements is greater than `X`.
211. Maximize Sum of a Subarray of Length K, where elements must be multiples of some P.
212. Minimize Sum of a Subarray of Length K, where elements must be multiples of some P.
213. Count Subarrays where all elements are powers of 2.
214. Find the Longest Subarray where all elements are powers of 2.
215. Count Subarrays with an even number of distinct elements.
216. Count Subarrays with an odd number of distinct elements.
217. Maximize Sum of a Subarray containing a specific pattern of elements.
218. Minimize Sum of a Subarray containing a specific pattern of elements.
219. Count Subarrays in a Binary Array where `count(1) == K` and `count(0) == M`.
220. Find the Longest Subarray in a Binary Array where `count(1) == K` and `count(0) == M`.
221. Count Subarrays in which all elements are within a given range `[Min, Max]`.
222. Find the Longest Subarray in which all elements are within a given range `[Min, Max]`.
223. Count Subarrays whose sum is a prime number.
224. Count Subarrays whose sum is a composite number.
225. Count Subarrays whose XOR sum is a prime number.
226. Count Subarrays whose XOR sum is a composite number.
227. Find Max Sum of a Subarray of Length K that includes a specific index `i`.
228. Find Min Sum of a Subarray of Length K that includes a specific index `i`.
229. Count Subarrays where the sum of its elements equals the sum of its indices, within a
window.
230. Find Longest Subarray where the sum of its elements equals the sum of its indices, within a
window.
231. Count Subarrays where `Array[i] % K == 0` for all elements in the window.
232. Count Subarrays where `Array[i] % K != 0` for all elements in the window.
233. Maximize Sum of a Subarray of Length K, where elements are taken from two different
arrays.
234. Minimize Sum of a Subarray of Length K, where elements are taken from two different
arrays.
235. Count Pairs `(i, j)` such that `Array[i] + Array[j]` equals `K` and `i, j` are in different halves of
the array.
236. Count Triplets `(i, j, k)` in a window of size `M` that sum to `S`.
237. Find Longest Subarray in a Binary Array that contains an even number of `1`s.
238. Find Longest Subarray in a Binary Array that contains an odd number of `1`s.
239. Count Subarrays where elements are distinct and form an arithmetic progression (Sliding
Window).
240. Find Longest Subarray where elements are distinct and form an arithmetic progression
(Sliding Window).
241. Count Subarrays where elements are distinct and form a geometric progression (Sliding
Window).
242. Find Longest Subarray where elements are distinct and form a geometric progression
(Sliding Window).
243. Count Subarrays containing at least one positive and one negative element (Sliding
Window).
244. Find Longest Subarray containing at least one positive and one negative element (Sliding
Window).
245. Count Subarrays where the sum of elements equals `K` and all elements are odd (Sliding
Window).
246. Find Longest Subarray where the sum of elements equals `K` and all elements are odd
(Sliding Window).
247. Count subarrays where average is within a specific range `[L,R]`.
248. Find longest subarray where average is within a specific range `[L,R]`.
249. Count subarrays where median is within a specific range `[L,R]`.
250. Find longest subarray where median is within a specific range `[L,R]`.

#### 8. Matrix Basics (2D Arrays) (Approx. 300 Problems)

**Fundamental Declarations, Access & Properties:**


1. Create Integer Matrix of Specified Dimensions.
2. Create Boolean Matrix of Specified Dimensions.
3. Access Element at `(Row, Column)` in Matrix.
4. Modify Element at `(Row, Column)` to New Value.
5. Print Matrix Contents Row by Row.
6. Print Matrix Contents Column by Column.
7. Search for Element in Unsorted Matrix.
8. Search for Element in Row-Sorted Matrix.
9. Search for Element in Row and Column Sorted Matrix.
10. Compute Sum of All Elements in Matrix.
11. Compute Sum of Specific Row in Matrix.
12. Compute Sum of Specific Column in Matrix.
13. Print Matrix Elements on its Boundary.
14. Count Occurrences of Value X in Matrix.
15. Check if Square Matrix is an Identity Matrix.
16. Check if Square Matrix is a Diagonal Matrix.
17. Check if Square Matrix is Symmetric.
18. Check if Square Matrix is Skew-Symmetric.
19. Perform Matrix Addition (Element-wise).
20. Perform Matrix Subtraction (Element-wise).
21. Perform Matrix Multiplication.
22. Reshape Matrix to New Dimensions (if compatible).
23. Calculate Island Perimeter in Binary Grid.
24. Count Distinct Islands in Binary Grid (DFS/BFS).
25. Find Maximum Island Area in Binary Grid.
26. Zero Out Row and Column if any element is Zero.
27. Simulate One Step of Conway's Game of Life.
28. Apply Image Averaging Filter to Matrix.
29. Check if Matrix is a Toeplitz Matrix.
30. Validate 9x9 Sudoku Board.
31. Count Battleships on a Board.
32. Count Negative Numbers in Sorted Matrix.
33. Sort Matrix Cells by Manhattan Distance from `(r0, c0)`.
34. Find Maximum Value in Matrix.
35. Find Minimum Value in Matrix.
36. Check if Matrix is Sparse.
37. Check if Matrix is Dense.
38. Count Paths from Top-Left to Bottom-Right in Grid (No Obstacles).
39. Calculate Minimum Path Sum in Grid (DP).
40. Calculate Maximum Path Sum in Grid (DP).
41. Calculate Minimum Falling Path Sum in Matrix.
42. Calculate Maximum Falling Path Sum in Matrix.
43. Find Longest Path in Binary Matrix (BFS/DFS).
44. Find Shortest Path in Binary Matrix (BFS).
45. Count Paths in Grid with Obstacles (DP).
46. Count Paths in Grid with Diagonal Moves.
47. Count Paths in Grid with Specific Jumps.
48. Maximize Product Path in a Grid.
49. Minimize Product Path in a Grid.
50. Find All Zero Rows in Matrix.

**Matrix Element Analysis:**


51. Find All Zero Columns in Matrix.
52. Find All Zero Submatrices.
53. Find All One Rows in Binary Matrix.
54. Find All One Columns in Binary Matrix.
55. Check if a Row Contains All Unique Elements.
56. Check if a Column Contains All Unique Elements.
57. Count Rows with All Even Numbers.
58. Count Rows with All Odd Numbers.
59. Count Columns with All Even Numbers.
60. Count Columns with All Odd Numbers.
61. Find Row with Maximum Sum.
62. Find Row with Minimum Sum.
63. Find Column with Maximum Sum.
64. Find Column with Minimum Sum.
65. Find Row with Maximum Average.
66. Find Row with Minimum Average.
67. Find Column with Maximum Average.
68. Find Column with Minimum Average.
69. Find Element that is a Local Max (Greater than all 8 neighbors).
70. Find Element that is a Local Min (Smaller than all 8 neighbors).
71. Count Local Maxima in Matrix.
72. Count Local Minima in Matrix.
73. Count Peak Elements in 2D Grid.
74. Count Valley Elements in 2D Grid.
75. Calculate Sum of Primary Diagonal Elements.
76. Calculate Sum of Secondary Diagonal Elements.
77. Calculate Sum of Elements Above Primary Diagonal.
78. Calculate Sum of Elements Below Primary Diagonal.
79. Calculate Sum of Elements Above Secondary Diagonal.
80. Calculate Sum of Elements Below Secondary Diagonal.

**Transformations & Manipulations (Excluding Rotations/Transposes which are separate


subtopic):**
81. Clear Matrix (Set all elements to 0).
82. Fill Matrix with a Constant Value.
83. Fill Matrix with Random Values within a Range.
84. Merge Two Matrices (Element-wise based on a rule).
85. Concatenate Two Matrices Side-by-Side.
86. Concatenate Two Matrices One Below Another.
87. Invert Binary Matrix (0->1, 1->0).
88. Convert 1D Array to 2D Matrix (Row-major).
89. Convert 1D Array to 2D Matrix (Column-major).
90. Convert 2D Matrix to 1D Array (Row-major).
91. Convert 2D Matrix to 1D Array (Column-major).
92. Find All Submatrices of Size KxK.
93. Count All Submatrices of Size KxK.
94. Count All Submatrices of All Sizes.
95. Generate All Possible Submatrices.
96. Find Largest Square Submatrix with Given Property.
97. Find Largest Rectangular Submatrix with Given Property.
98. Find Max Value in a `K x K` Submatrix (for each `(r, c)`).
99. Find Min Value in a `K x K` Submatrix (for each `(r, c)`).
100. Find Sum of All `K x K` Submatrices.

**Advanced Matrix Problems:**


101. Maximal Square (Binary Matrix DP).
102. Maximal Rectangle (Binary Matrix DP).
103. Count Square Submatrices with All Ones.
104. Count Rectangular Submatrices with All Ones.
105. Largest Plus Sign (Matrix DP).
106. Number of Provinces (Graph problem on matrix representation).
107. Flood Fill Algorithm.
108. Pacific Atlantic Water Flow (DFS/BFS).
109. Shortest Bridge (BFS on Islands).
110. Number of Closed Islands.
111. Surrounded Regions (BFS/DFS Boundary).
112. Minesweeper Game (Click event simulation).
113. Find a Peak Element in a 2D Grid.
114. Count Paths with XOR Sum K in Grid.
115. Count Paths with Sum S in Grid.
116. Count Paths with Product P in Grid.
117. Find All Shortest Paths in Matrix.
118. Find All Longest Paths in Matrix.
119. Shortest Path in Grid with Obstacles Elimination.
120. Cherry Pickup (Two-agent DP on grid).
121. Dungeon Game (Grid DP with negative values).
122. Walk on Grid with Minimum Cost.
123. Count Subgrids with Same Values (Binary Matrix).
124. Number of Ways to Cut a Pizza (DP).
125. Find the Kth Smallest Element in a Sorted Matrix.
126. Find the Median of a Row-wise Sorted Matrix.
127. Find All Critical Connections in a Network (Matrix as Adjacency).
128. Find All Articulation Points in a Graph (Matrix as Adjacency).
129. Check if Matrix is a Magic Square.
130. Check if Matrix is Latin Square.
131. Convert Matrix to Sparse Matrix Representation.
132. Convert Sparse Matrix to Dense Matrix Representation.
133. Find Longest Common Submatrix of Two Binary Matrices.
134. Count Distinct Shapes of Islands.
135. Minimum Moves to Move a Box to Target (BFS on 2D state).
136. Find Maximum Product Path in a Grid.
137. Find Minimum Product Path in a Grid.
138. Count Paths Where Sum is Divisible by K.
139. Count Paths Where Product is Divisible by K.
140. Count Paths Where XOR Sum is Divisible by K.
141. Find the Kth Path in a Grid (Lexicographically).
142. Find Maximum Value in a Grid with Jumps (DP).
143. Find Minimum Value in a Grid with Jumps (DP).
144. Count Paths from Start to End with Exactly K Turns.
145. Find Max Score by Collecting All Gold from Mines (DP).
146. Find the Longest Snake Sequence in a Grid.
147. Count All Cells in Matrix in Spiral Order (starting from `(r,c)`).
148. Find the Number of Ways to Reach Cell `(r, c)` from `(0, 0)` with obstacles.
149. Count Subgrids where all cells are `0`s.
150. Count Subgrids where all cells are `1`s.
151. Find the Maximum Number of "X"s in a Plus Sign Shape.
152. Find the Maximum Number of "0"s in a Plus Sign Shape.
153. Count Submatrices that are Palindromic (if rows/columns viewed as strings).
154. Find the Number of Ways to Divide a Grid into K Regions.
155. Find the Minimum Time to Visit All Cells in a Grid.
156. Count Paths of Length K in a Grid.
157. Find the Minimum Cost to Cross a Grid with Portals.
158. Find the Maximum Number of Fruits You Can Collect from a Grid.
159. Count the Number of Towers You Can Build on a Grid.
160. Find the Largest Connected Component of Same-Valued Elements.
161. Count Connected Components of Same-Valued Elements.
162. Find the Maximum Number of Safe Paths in a Grid.
163. Find the Minimum Number of Moves to Collect All Items in a Grid.
164. Find the Minimum Number of Moves to Push a Block Through a Maze.
165. Count Paths in a Grid that do not cross a boundary.
166. Count Paths in a Grid that must pass through a specific cell.
167. Find the Number of "Good" Cells in a Matrix (satisfying specific conditions related to
neighbors).
168. Find the Maximum Value in a `K x K` Submatrix for all possible `K x K` submatrices.
169. Find the Minimum Value in a `K x K` Submatrix for all possible `K x K` submatrices.
170. Find the Sum of All `K x K` Submatrices.
171. Find the Average of All `K x K` Submatrices.
172. Count Submatrices where the sum of elements is equal to the sum of their row/column
indices.
173. Find the Largest Square Submatrix whose diagonal elements are identical.
174. Find the Largest Rectangular Submatrix whose border elements are identical.
175. Count Rectangles that can be formed by cells with specific values.
176. Find the Number of ways to color a grid with K colors such that no two adjacent cells have
the same color.
177. Find the Maximum Sum of elements in an L-shaped region of a matrix.
178. Find the Minimum Sum of elements in an L-shaped region of a matrix.
179. Find the Number of ways to tile a grid with given domino shapes.
180. Find the longest path in a matrix such that elements are strictly increasing by 1.
181. Find the shortest path in a matrix such that elements are strictly decreasing by 1.
182. Find the number of cells `(r, c)` such that `matrix[r][c]` is the maximum in its row.
183. Find the number of cells `(r, c)` such that `matrix[r][c]` is the minimum in its row.
184. Find the number of cells `(r, c)` such that `matrix[r][c]` is the maximum in its column.
185. Find the number of cells `(r, c)` such that `matrix[r][c]` is the minimum in its column.
186. Find the number of cells `(r, c)` such that `matrix[r][c]` is both a row maximum and a column
minimum.
187. Find the number of cells `(r, c)` such that `matrix[r][c]` is both a row minimum and a column
maximum.
188. Find the number of cells `(r, c)` such that `matrix[r][c]` is an even number and its neighbors
are all odd.
189. Find the number of cells `(r, c)` such that `matrix[r][c]` is an odd number and its neighbors
are all even.
190. Count paths from `(r1, c1)` to `(r2, c2)` in a grid.
191. Find the shortest path from `(r1, c1)` to `(r2, c2)` in a grid.
192. Find the longest path from `(r1, c1)` to `(r2, c2)` in a grid.
193. Find all paths from `(r1, c1)` to `(r2, c2)` in a grid.
194. Find the number of pairs of `(r, c)` that are `K` distance apart.
195. Find the `K` closest cells to a given cell `(r0, c0)`.
196. Find the `K` farthest cells from a given cell `(r0, c0)`.
197. Determine if a path exists from `(r1, c1)` to `(r2, c2)` passing through `(rx, cx)`.
198. Count elements that are `K` distance away from a target element in the matrix.
199. Find the maximum sum of a submatrix where all elements are positive.
200. Find the minimum sum of a submatrix where all elements are negative.

#### 9. Spiral Traversal & Diagonal Traversal (Approx. 150 Problems)

**Spiral Traversal:**
1. Collect All Elements in Clockwise Spiral Order.
2. Collect All Elements in Counter-Clockwise Spiral Order.
3. Generate Matrix with Numbers 1 to N^2 in Clockwise Spiral Order.
4. Generate Matrix with Numbers 1 to N^2 in Counter-Clockwise Spiral Order.
5. Traverse Matrix in Spiral Order Starting from `(r0, c0)`.
6. Print Matrix Boundary Elements in Clockwise Spiral Order.
7. Print Matrix Boundary Elements in Counter-Clockwise Spiral Order.
8. Find Kth Element in Spiral Order Traversal.
9. Find Coordinates of Kth Element in Spiral Order Traversal.
10. Determine if Element is Visited in Spiral Traversal.
11. Convert 1D Array to 2D Matrix in Spiral Order.
12. Fill Matrix in Spiral Order from a Given Sequence.
13. Spiral Traversal of a Sparse Matrix.
14. Spiral Traversal of a Matrix with Obstacles.
15. Count Elements Visited in Spiral Traversal.
16. Sum Elements Visited in Spiral Traversal.
17. Maximize Sum of Elements in a Spiral Path.
18. Minimize Sum of Elements in a Spiral Path.
19. Find First Even Number in Spiral Path.
20. Find First Odd Number in Spiral Path.
21. Find First Prime Number in Spiral Path.
22. Reverse Spiral Order Traversal.
23. Spiral Traversal of Rectangular Matrix (m x n).
24. Spiral Traversal of Irregular Shaped Matrix.
25. Find Path Length of Spiral Traversal.
26. Count Layers in Spiral Traversal.
27. Collect Elements from Outer Layer in Spiral Order.
28. Collect Elements from Inner Layer in Spiral Order.
29. Collect Elements from All Layers in Spiral Order.
30. Check if a Given Path is a Valid Spiral Traversal.
**Diagonal Traversal:**
31. Collect All Elements in Diagonal Order (Top-Left to Bottom-Right).
32. Collect All Elements in Anti-Diagonal Order (Top-Right to Bottom-Left).
33. Collect All Elements in Zigzag Diagonal Order.
34. Find Kth Element in Diagonal Order Traversal.
35. Find Coordinates of Kth Element in Diagonal Order Traversal.
36. Determine if Element is Visited in Diagonal Traversal.
37. Convert 1D Array to 2D Matrix in Diagonal Order.
38. Fill Matrix in Diagonal Order from a Given Sequence.
39. Diagonal Traversal of a Sparse Matrix.
40. Diagonal Traversal of a Matrix with Obstacles.
41. Count Elements Visited in Diagonal Traversal.
42. Sum Elements Visited in Diagonal Traversal.
43. Maximize Sum of Elements in a Diagonal Path.
44. Minimize Sum of Elements in a Diagonal Path.
45. Find First Even Number in Diagonal Path.
46. Find First Odd Number in Diagonal Path.
47. Find First Prime Number in Diagonal Path.
48. Reverse Diagonal Order Traversal.
49. Diagonal Traversal of Rectangular Matrix (m x n).
50. Diagonal Traversal of Irregular Shaped Matrix.
51. Find Path Length of Diagonal Traversal.
52. Count Diagonals in Matrix.
53. Collect Elements from Specific Diagonal.
54. Check if a Given Path is a Valid Diagonal Traversal.
55. Sort Elements Along Each Diagonal.
56. Sort Elements Along Each Anti-Diagonal.
57. Check if All Diagonal Elements are Same.
58. Check if All Anti-Diagonal Elements are Same.
59. Sum of Elements on Specific Diagonal.
60. Product of Elements on Specific Diagonal.

**Combined & Advanced Traversal:**


61. Traverse Matrix in Snake Pattern (Row-wise Alternating).
62. Traverse Matrix in Column-wise Snake Pattern.
63. Print All Paths from Top-Left to Bottom-Right (Various Traversal Orders).
64. Find All Paths with a Given Sum (Matrix Traversal).
65. Find Longest Path with Increasing Values (Matrix Traversal).
66. Find Shortest Path with Decreasing Values (Matrix Traversal).
67. Count Specific Paths in Grid (e.g., paths divisible by K).
68. Wave Traversal of Matrix.
69. Print Matrix Layers in Spiral Order.
70. Fill Matrix Layers in Spiral Order.
71. Search for a Target Element by Spiral Traversal.
72. Search for a Target Element by Diagonal Traversal.
73. Find Max Sum in an L-shaped region of a matrix (can use clever traversal).
74. Find Min Sum in an L-shaped region of a matrix.
75. Count Cells Visited by Both Spiral and Diagonal Traversal.
76. Sum Cells Visited by Both Spiral and Diagonal Traversal.
77. Find Kth Common Element in Spiral and Diagonal Traversal.
78. Determine if a Given Number Can Be Formed by Summing Elements Along a Spiral Path.
79. Determine if a Given Number Can Be Formed by Summing Elements Along a Diagonal Path.
80. Find Longest Spiral Path with Unique Elements.
81. Find Longest Diagonal Path with Unique Elements.
82. Count Spiral Paths that are Palindromic.
83. Count Diagonal Paths that are Palindromic.
84. Fill Matrix in a Combined Spiral-Diagonal Pattern.
85. Collect Elements from a Spiral Path within a Bounded Box.
86. Collect Elements from a Diagonal Path within a Bounded Box.
87. Find Maximum XOR Sum Along a Spiral Path.
88. Find Maximum XOR Sum Along a Diagonal Path.
89. Count Distinct Elements in a Spiral Path.
90. Count Distinct Elements in a Diagonal Path.
91. Find Largest Element in a Spiral Path.
92. Find Smallest Element in a Spiral Path.
93. Find Largest Element in a Diagonal Path.
94. Find Smallest Element in a Diagonal Path.
95. Find the Number of Spiral Paths that form an Arithmetic Progression.
96. Find the Number of Diagonal Paths that form an Arithmetic Progression.
97. Find the Longest Spiral Path that forms an Arithmetic Progression.
98. Find the Longest Diagonal Path that forms an Arithmetic Progression.
99. Count Spiral Paths with Alternating Parity.
100. Count Diagonal Paths with Alternating Parity.
101. Find Longest Spiral Path with Alternating Parity.
102. Find Longest Diagonal Path with Alternating Parity.
103. Generate a Matrix filled with increasing numbers but in anti-diagonal order.
104. Generate a Matrix filled with increasing numbers but in zigzag anti-diagonal order.
105. Find the number of times a particular value `X` appears in spiral traversal.
106. Find the number of times a particular value `X` appears in diagonal traversal.
107. Find first element in spiral traversal that is greater than its predecessor.
108. Find first element in diagonal traversal that is greater than its predecessor.
109. Find the sum of elements in the outermost layer of a matrix using spiral traversal.
110. Find the sum of elements in the innermost layer of a matrix using spiral traversal.
111. Find the product of elements in the outermost layer of a matrix using spiral traversal.
112. Find the product of elements in the innermost layer of a matrix using spiral traversal.
113. Count elements in a specific diagonal that are prime.
114. Count elements in a specific anti-diagonal that are prime.
115. Count elements in a specific diagonal that are composite.
116. Count elements in a specific anti-diagonal that are composite.
117. Check if a matrix can be constructed from a given spiral sequence.
118. Check if a matrix can be constructed from a given diagonal sequence.
119. Find the maximum element among elements visited in a clockwise spiral path.
120. Find the minimum element among elements visited in a clockwise spiral path.
121. Find the average of elements visited in a clockwise spiral path.
122. Find the average of elements visited in a diagonal path.
123. Count unique elements visited in a clockwise spiral path.
124. Count unique elements visited in a diagonal path.
125. Find the Kth element in a spiral path starting from the center of the matrix.
126. Find the Kth element in a diagonal path starting from the top-right corner.
127. Find the path with the largest sum following a spiral pattern, restricted to a subgrid.
128. Find the path with the smallest sum following a spiral pattern, restricted to a subgrid.
129. Find the path with the largest sum following a diagonal pattern, restricted to a subgrid.
130. Find the path with the smallest sum following a diagonal pattern, restricted to a subgrid.
131. Count the number of cells that are part of both the primary and secondary diagonals.
132. Count the number of cells that are part of both the outermost and innermost spiral layers.
133. Find the path with the maximum XOR sum following a spiral pattern.
134. Find the path with the maximum XOR sum following a diagonal pattern.
135. Find the path with the minimum XOR sum following a spiral pattern.
136. Find the path with the minimum XOR sum following a diagonal pattern.
137. Generate a matrix filled with alternating values (e.g., 0, 1) in a spiral fashion.
138. Generate a matrix filled with alternating values in a diagonal fashion.
139. Given a binary matrix, find the longest spiral path consisting entirely of 1s.
140. Given a binary matrix, find the longest diagonal path consisting entirely of 1s.
141. Determine if a specific value `X` can be reached by following a spiral path.
142. Determine if a specific value `X` can be reached by following a diagonal path.
143. Count the number of times the value changes along a spiral path.
144. Count the number of times the value changes along a diagonal path.
145. Find the longest increasing sequence along a spiral path.
146. Find the longest increasing sequence along a diagonal path.
147. Find the longest decreasing sequence along a spiral path.
148. Find the longest decreasing sequence along a diagonal path.
149. Sum all elements in the matrix layer by layer (spiral approach).
150. Sum all elements in the matrix diagonal by diagonal.

#### 10. Rotate & Transpose Matrix (Approx. 150 Problems)

**Rotations:**
1. Rotate Square Matrix 90 Degrees Clockwise In-place.
2. Rotate Square Matrix 90 Degrees Anti-Clockwise In-place.
3. Rotate Square Matrix 180 Degrees In-place.
4. Rotate Square Matrix 270 Degrees Clockwise In-place.
5. Rotate Square Matrix 270 Degrees Anti-Clockwise In-place.
6. Rotate Rectangular Matrix 90 Degrees Clockwise (to new matrix).
7. Rotate Rectangular Matrix 90 Degrees Anti-Clockwise (to new matrix).
8. Rotate Rectangular Matrix 180 Degrees (to new matrix).
9. Rotate Rectangular Matrix 270 Degrees (to new matrix).
10. Check if Matrix Can Be Obtained by Rotating Another Matrix 90 Degrees.
11. Check if Matrix Can Be Obtained by Rotating Another Matrix 180 Degrees.
12. Find Minimum Number of 90-Degree Rotations to Match Target Matrix.
13. Perform K 90-Degree Clockwise Rotations on Square Matrix.
14. Perform K 90-Degree Anti-Clockwise Rotations on Square Matrix.
15. Rotate Outer Layer of Matrix Clockwise.
16. Rotate Outer Layer of Matrix Anti-Clockwise.
17. Rotate All Layers of Matrix Clockwise.
18. Rotate All Layers of Matrix Anti-Clockwise.
19. Rotate Specific Layer of Matrix by K Positions.
20. Rotate Matrix Elements Along a Specific Diagonal.
21. Rotate Matrix Elements Along a Specific Anti-Diagonal.
22. Rotate Matrix Elements Clockwise Along its Boundary.
23. Rotate Matrix Elements Anti-Clockwise Along its Boundary.
24. Rotate a Row of a Matrix by K Positions.
25. Rotate a Column of a Matrix by K Positions.
26. Find Kth Element After N Rotations (90 degrees).
27. Simulate Rotation of Matrix Cells.
28. Rotate Submatrix within a Larger Matrix.
29. Rotate Binary Matrix (Optimize for 0/1 values).
30. Rotate Matrix with Character Elements.
**Transpositions:**
31. Compute Transpose of a Rectangular Matrix (to new matrix).
32. Compute Transpose of a Square Matrix In-place.
33. Compute Conjugate Transpose of a Complex Matrix.
34. Check if Matrix is Symmetric (via Transpose).
35. Check if Matrix is Skew-Symmetric (via Transpose).
36. Check if Matrix is Self-Transpose (Identity or equivalent).
37. Check if Matrix is Transpose of Another Matrix.
38. Perform Transposition and then Reverse Rows.
39. Perform Transposition and then Reverse Columns.
40. Find Kth Element in Transposed Matrix.
41. Find Coordinates of Kth Element in Transposed Matrix.
42. Transpose a Sparse Matrix Efficiently.
43. Transpose Submatrix within a Larger Matrix.
44. Find All Symmetric Submatrices.
45. Find All Skew-Symmetric Submatrices.
46. Count Pairs `(i, j)` such that `Matrix[i][j] == Transpose[i][j]`.
47. Count Pairs `(i, j)` such that `Matrix[i][j] != Transpose[i][j]`.
48. Maximize Sum of Diagonal After Transpose.
49. Minimize Sum of Diagonal After Transpose.
50. Verify `(A * B)^T == B^T * A^T`.

**Flips & Reflections:**


51. Flip Binary Image Horizontally and Invert.
52. Flip Binary Image Vertically and Invert.
53. Reflect Matrix Horizontally.
54. Reflect Matrix Vertically.
55. Reflect Matrix Along Primary Diagonal.
56. Reflect Matrix Along Secondary Diagonal.
57. Check if Matrix is Reflection of Another Matrix (Horizontal).
58. Check if Matrix is Reflection of Another Matrix (Vertical).
59. Count Number of Reflections to Match Target Matrix.
60. Flip Rows with All Ones.
61. Flip Columns with All Ones.
62. Flip Rows with All Zeroes.
63. Flip Columns with All Zeroes.
64. Flip Elements of a Specific Row.
65. Flip Elements of a Specific Column.
66. Flip Elements Along a Specific Diagonal.
67. Flip Elements Along a Specific Anti-Diagonal.
68. Flip Matrix to Achieve Max Sum of Row/Column.
69. Flip Matrix to Achieve Min Sum of Row/Column.
70. Flip Matrix to Maximize Number of `1`s.
71. Flip Matrix to Minimize Number of `1`s.
72. Flip Matrix to Maximize Product.
73. Flip Matrix to Minimize Product.
74. Find All Possible Matrices Obtainable by K Flips.
75. Determine if Matrix can be Made Symmetric by Flips.

**Combined Operations & Advanced Variants:**


76. Check if Matrix A can become Matrix B by sequence of rotations/flips.
77. Find Minimum Operations (Rotations/Flips) to Transform Matrix A to B.
78. Image Overlap (Shifting + Rotation/Flip).
79. Rotate Array (1D) by K Positions (Conceptual relation to matrix rotation).
80. Rotate Elements on Clockwise Boundary and Shift Inwards.
81. Rotate Elements on Anti-Clockwise Boundary and Shift Inwards.
82. Rotate Layers of Matrix Independently.
83. Permute Rows of Matrix.
84. Permute Columns of Matrix.
85. Apply K Random Rotations to a Matrix.
86. Apply K Random Flips to a Matrix.
87. Maximize Sum of Elements in a Row after One Rotation.
88. Maximize Sum of Elements in a Column after One Rotation.
89. Maximize Product of Elements in a Row after One Rotation.
90. Maximize Product of Elements in a Column after One Rotation.
91. Find All Rotations of a Submatrix.
92. Find All Transpositions of a Submatrix.
93. Count Number of Unique Matrices Obtainable from Rotations.
94. Count Number of Unique Matrices Obtainable from Flips.
95. Determine if a Given Pattern Exists in Any Rotation of Matrix.
96. Determine if a Given Pattern Exists in Any Transposition of Matrix.
97. Rotate 2D Array by arbitrary degrees (e.g., 45 degrees, complex).
98. Rotate a Cube (3D Matrix) by 90 Degrees.
99. Transpose a Cube (3D Matrix).
100. Find Most Frequent Row after All Possible Rotations.
101. Find Most Frequent Column after All Possible Rotations.
102. Maximize Sum of Elements in a Specific Path after Rotations.
103. Minimize Sum of Elements in a Specific Path after Rotations.
104. Find the Number of Rotations to Align Two Patterns in a Matrix.
105. Find the Number of Flips to Align Two Patterns in a Matrix.
106. Apply Rotations to Achieve Maximize Diagonal Sum.
107. Apply Rotations to Achieve Minimize Diagonal Sum.
108. Apply Transpositions to Achieve Maximize Diagonal Sum.
109. Apply Transpositions to Achieve Minimize Diagonal Sum.
110. Rotate Matrix Layers by K Steps (independent K for each layer).
111. Shift Each Row Left by its Index.
112. Shift Each Row Right by its Index.
113. Shift Each Column Up by its Index.
114. Shift Each Column Down by its Index.
115. Find all permutations of rows that make a matrix sorted by columns.
116. Find all permutations of columns that make a matrix sorted by rows.
117. Count Number of Square Submatrices that become Symmetric after one rotation.
118. Count Number of Rectangular Submatrices that become Symmetric after one transpose.
119. Find the Maximize Value of `(Matrix[i][j] + Matrix[Rotated_Matrix[i][j]])`.
120. Find the Minimum Value of `(Matrix[i][j] + Matrix[Rotated_Matrix[i][j]])`.
121. Find the Maximum Value of `(Matrix[i][j] + Matrix[Transposed_Matrix[i][j]])`.
122. Find the Minimum Value of `(Matrix[i][j] + Matrix[Transposed_Matrix[i][j]])`.
123. Count elements that remain in the same position after `K` rotations.
124. Count elements that return to the same position after `K` rotations.
125. Count elements that move to a new position after `K` rotations.
126. Count pairs `(i, j)` where `Matrix[i][j]` is unchanged after a horizontal flip and `Matrix[j][i]` is
unchanged after a vertical flip.
127. Find the Longest Palindromic Row after any number of rotations.
128. Find the Longest Palindromic Column after any number of rotations.
129. Maximize the number of consecutive `1`s in a row after one rotation of the matrix.
130. Maximize the number of consecutive `1`s in a column after one rotation of the matrix.
131. Rotate Submatrices such that their sum is maximized.
132. Transpose Submatrices such that their sum is maximized.
133. Find Minimum Cost to Make Matrix Symmetric by flipping rows/columns.
134. Find Minimum Cost to Make Matrix Symmetric by swapping rows/columns.
135. Find Minimum Cost to Make Matrix Identical by rotations/transpositions/flips.
136. Find all `(r, c)` pairs such that `Matrix[r][c]` becomes `Matrix[c][r]` after one transpose.
137. Find all `(r, c)` pairs such that `Matrix[r][c]` becomes `Matrix[N-1-r][N-1-c]` after 180 degree
rotation.
138. Generate all unique matrices by applying all combinations of rotations and flips.
139. Given a character matrix, determine if a given word can be formed by starting at any cell and
moving in a spiral fashion within a submatrix.
140. Given a character matrix, determine if a given word can be formed by starting at any cell and
moving in a diagonal fashion within a submatrix.
141. Find the maximum sum of a row that is a palindrome after applying any single column
rotation.
142. Find the maximum sum of a column that is a palindrome after applying any single row
rotation.
143. Count the number of rows that are identical to any column after transposition.
144. Count the number of columns that are identical to any row after transposition.
145. Find the minimum number of row swaps and column swaps to make a matrix symmetric.
146. Find the maximum product of elements on a diagonal after applying `K` rotations.
147. Find the minimum product of elements on a diagonal after applying `K` rotations.
148. Maximize the number of '1's on the main diagonal after any 90-degree rotations.
149. Minimize the number of '1's on the main diagonal after any 90-degree rotations.
150. Count unique 2D array configurations achievable by all combinations of 90-degree rotations
and horizontal/vertical flips.

---

### Final Problem Count:

1. **Basics of Arrays & Memory Layout:** 300 problems


2. **Traversal & Basic Operations (Insert/Delete/Update):** 300 problems
3. **Prefix Sum & Difference Array:** 300 problems
4. **Subarrays & Subsequence Basics:** 300 problems
5. **Kadane’s Algorithm (Max Subarray Sum):** 300 problems
6. **Two Pointers Technique:** 300 problems
7. **Sliding Window Technique:** 250 problems
8. **Matrix Basics (2D Arrays):** 200 problems
9. **Spiral Traversal & Diagonal Traversal:** 150 problems
10. **Rotate & Transpose Matrix:** 150 problems

You might also like