Huge collection of Array Interview Questions

Vivek Srivastava
Techie Delight

--

An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. The simplest type of data structure is a linear array, also called a one-dimensional array.

Arrays are among the oldest and most important data structures and are used by almost every program. They are also used to implement many other data structures, such as lists, heaps, hash tables, deques, queues, stacks, strings.

An array as 10 boxes numbered 0 through 9; an index of 0

In this post, we have listed out commonly asked interview questions that use array data structure:

  1. Find a pair with the given sum in an array
  2. Check if a subarray with 0 sum exists or not
  3. Print all subarrays with 0 sum
  4. Sort binary array in linear time
  5. Find maximum length subarray having a given sum
  6. Find maximum length subarray having an equal number of 0’s and 1’s
  7. Find the maximum product of two integers in an array
  8. Sort an array of 0’s, 1’s, and 2’s (Dutch National Flag Problem)
  9. In-place merge two sorted arrays
  10. Merge two arrays by satisfying given constraints
  11. Find the index of 0 to be replaced to get the maximum length sequence of continuous ones
  12. Shuffle an array using Fisher–Yates shuffle algorithm
  13. Rearrange an array with alternate high and low elements
  14. Find equilibrium index of an array
  15. Find the largest subarray formed by consecutive integers
  16. Find majority element (Boyer–Moore Majority Vote Algorithm)
  17. Move all zeros present in an array to the end
  18. Replace every array element with the product of every other element
  19. Longest Bitonic Subarray Problem
  20. Find the maximum difference between two array elements that satisfies the given constraints
  21. Print continuous subarray with maximum sum
  22. Maximum Sum Circular Subarray
  23. Find all distinct combinations of a given length — I
  24. Find the maximum sequence of continuous 1’s formed by replacing at-most `k` zeroes by ones
  25. Find minimum sum subarray of size `k`
  26. Maximum Product Subarray Problem
  27. Find a subarray having the given sum in an integer array
  28. Find the smallest subarray length whose sum of elements is greater than `k`
  29. Find the smallest window in an array sorting which will make the entire array sorted
  30. Find maximum sum path involving elements of given arrays
  31. Find maximum profit earned by buying and selling shares any number of times
  32. Trapping Rain Water Problem
  33. Find minimum platforms needed to avoid delay in the train arrival
  34. Decode an array constructed from another array
  35. Sort an array in one swap whose two elements are swapped
  36. Find a triplet with the given sum in an array
  37. Find the length of the longest continuous sequence with the same sum in given binary arrays
  38. Reverse every consecutive `m`-elements of a subarray
  39. Maximum Product Subset Problem
  40. Find pairs with difference `k` in an array
  41. 4–Sum Problem | Quadruplets with a given sum
  42. Print all quadruplets with a given sum | 4 sum problem extended
  43. Quickselect Algorithm
  44. Rearrange array such that `A[A[i]]` is set to `i` for every element `A[i]`
  45. Print all triplets that form an arithmetic progression
  46. Print all triplets that form a geometric progression
  47. Group elements of an array based on their first occurrence
  48. Find the minimum difference between the index of two given elements present in an array
  49. Find the maximum absolute difference between the sum of two non-overlapping subarrays
  50. Find all symmetric pairs in an array of pairs
  51. Find the closest pair to a given sum in two sorted arrays
  52. Partition an array into two subarrays with the same sum
  53. Find the count of distinct elements in every subarray of size `k`
  54. Find two numbers with maximum sum formed by array digits
  55. Print all subarrays of an array having distinct elements
  56. Find a triplet having the maximum product in an array
  57. Find the minimum index of a repeating element in an array
  58. Find a pair with a minimum absolute sum in an array
  59. Find an index of the maximum occurring element with equal probability
  60. Check if an array is formed by consecutive integers
  61. Find two non-overlapping pairs having the same sum in an array
  62. Add elements of two arrays into a new array
  63. Find minimum product among all combinations of triplets in an array
  64. Count distinct absolute values in a sorted array
  65. Print all combinations of positive integers in increasing order that sums to a given number
  66. Find all distinct combinations of a given length — II
  67. Find subarrays with a given sum in an array
  68. Find maximum length sequence of continuous ones (Using Sliding Window)
  69. Find maximum length sequence of continuous ones
  70. Find the index that divides an array into two non-empty subarrays with equal sum
  71. Efficiently calculate the frequency of all elements present in a limited range array
  72. Rearrange an array such that it contains positive and negative numbers at alternate positions
  73. Find the sorted triplet in an array
  74. Shuffle an array according to the given order of elements
  75. Count the number of strictly increasing subarrays in an array
  76. Find duplicates within a range `k` in an array
  77. Find a minimum range with at least one element from each of the given arrays
  78. Find the longest subsequence formed by consecutive integers
  79. Determine the index of an element that satisfies given constraints in an array
  80. Find minimum moves required for converting a given array to an array of zeroes
  81. Left rotate an array
  82. Right rotate an array `k` times
  83. Activity Selection Problem
  84. Job Sequencing Problem with Deadlines
  85. 3–partition problem extended | Printing all partitions
  86. Count triplets which form an inversion in an array
  87. Determine whether an array can be divided into pairs with a sum divisible by `k`
  88. Find minimum removals required in an array to satisfy given constraints
  89. Find a pair with the given sum in a circularly sorted array
  90. Segregate positive and negative integers in linear time
  91. Find the minimum and maximum element in an array using minimum comparisons
  92. Insertion Sort Algorithm
  93. Selection Sort Algorithm
  94. Bubble Sort Algorithm
  95. Merge Sort Algorithm
  96. Iterative Merge Sort Algorithm (Bottom-up Merge Sort)
  97. Quicksort Algorithm
  98. Hybrid QuickSort Algorithm
  99. Quicksort using Dutch National Flag Algorithm
  100. Quicksort algorithm using Hoare’s partitioning scheme
  101. Counting Sort Algorithm
  102. Heap Sort Algorithm
  103. Introsort Algorithm — Overview and C++ Implementation
  104. External Merge Sort Algorithm
  105. Inversion count of an array
  106. Problems solved using partitioning logic of Quicksort
  107. Sort elements by their frequency and index
  108. Sort an array based on order defined by another array
  109. Efficiently sort an array with many duplicated values
  110. Find the largest number possible from a given set of numbers
  111. Find surpasser count for each array element
  112. Segregate positive and negative integers using merge sort
  113. Water Jugs Problem
  114. Sort an array using Young tableau
  115. Find all combinations of elements satisfying given constraints
  116. K–Partition Problem | Printing all partitions
  117. Find all distinct combinations of a given length with repetition allowed
  118. Print all combinations of numbers from 1 to `n` having sum `n`
  119. Print all triplets in an array with a sum less than or equal to a given number
  120. Difference between Subarray, Subsequence, and Subset
  121. Print all distinct subsets of a given set
  122. Find the missing number in an array
  123. Find the missing number in an array without using any extra space
  124. Find the odd occurring element in an array in a single traversal
  125. Find two odd occurring elements in an array without using any extra space
  126. Find all odd occurring elements in an array having a limited range of elements
  127. Find the duplicate element in a limited range array
  128. Find two duplicate elements in a limited range array (using XOR)
  129. Find the missing number and duplicate elements in an array
  130. Merging Overlapping Intervals
  131. Maximum Overlapping Intervals Problem
  132. Find the next greater element for every element in a circular array
  133. Find the next greater element for every array element
  134. Find the previous smaller element for each array element
  135. Reverse an array in C++
  136. Longest Increasing Subsequence Problem
  137. Find all elements in an array that are greater than all elements to their right
  138. Iterative Implementation of Quicksort
  139. Combinations of words formed by replacing given numbers with corresponding alphabets
  140. Replace every array element with the least greater element on its right
  141. Print complete Binary Search Tree (BST) in increasing order
  142. Binary Search Algorithm
  143. Find the number of rotations in a circularly sorted array
  144. Search an element in a circularly sorted array
  145. Find the first or last occurrence of a given number in a sorted array
  146. Count occurrences of a number in a sorted array with duplicates
  147. Find the smallest missing element from a sorted array
  148. Find floor and ceil of a number in a sorted integer array
  149. Search in a nearly sorted array in logarithmic time
  150. Find the number of 1’s in a sorted binary array
  151. Find the peak element in an array
  152. Maximum Subarray Sum using Divide and Conquer
  153. Find the missing term in a sequence in logarithmic time
  154. Find floor and ceil of a number in a sorted array (Recursive solution)
  155. Find the frequency of each element in a sorted array containing duplicates
  156. Find the odd occurring element in an array in logarithmic time
  157. Find pairs with difference `k` in an array | Constant Space Solution
  158. Find `k` closest elements to a given value in an array
  159. Find the minimum and maximum element in an array using Divide and Conquer
  160. Binary Search in C++ STL and Java Collections
  161. Ternary Search vs Binary search
  162. Exponential search
  163. Interpolation search
  164. Longest Increasing Subsequence using Dynamic Programming
  165. Longest Decreasing Subsequence Problem
  166. Longest Bitonic Subsequence
  167. Maximum Sum Increasing Subsequence Problem
  168. Matrix Chain Multiplication using Dynamic Programming
  169. 0–1 Knapsack Problem
  170. Maximize the value of an expression
  171. Partition Problem using Dynamic Programming
  172. Subset Sum Problem — Dynamic Programming Solution
  173. 3–Partition Problem
  174. Minimum Sum Partition Problem
  175. Rod Cutting Problem
  176. Coin change-making problem
  177. Coin Change Problem
  178. Longest Alternating Subsequence Problem
  179. Weighted Interval Scheduling Problem
  180. Box Stacking Problem
  181. Activity Selection Problem using Dynamic Programming
  182. Weighted Interval Scheduling — Dynamic Programming Solution
  183. Find minimum jumps required to reach the destination
  184. Find maximum profit earned from at most `k` stock transactions
  185. Find the maximum sum of a subsequence with no adjacent elements
  186. Minimum-weight triangulation of a convex polygon
  187. Find maximum profit that can be earned by conditionally selling stocks
  188. Truncate an integer array such that `2×min` becomes more than `max`
  189. Maximum Sum Subarray Problem (Kadane’s Algorithm)
  190. Longest Alternating Subarray Problem
  191. Find maximum profit earned from at most two stock transactions
  192. Find ways to calculate a target from elements of the specified array
  193. Find itinerary from the given list of departure and arrival airports
  194. Introduction to Priority Queues using Binary Heaps
  195. Check if an array represents a min-heap or not
  196. Convert max heap to min heap in linear time
  197. Find k’th largest element in an array
  198. Sort a k-sorted array
  199. Merge `M` sorted lists of variable length
  200. Find k’th smallest element in an array
  201. Find the smallest range with at least one element from each of the given lists
  202. Merge `M` sorted lists each containing `N` elements
  203. Connect `n` ropes with minimal cost
  204. Replace each array element by its corresponding rank
  205. Generate the power set of a given set
  206. Set both elements of a binary array to 0 in a single line
  207. Generate random input from an array according to given probabilities

Thanks for reading.

--

--