Huge collection of Array Interview Questions
Published in
8 min readDec 15, 2018
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.
In this post, we have listed out commonly asked interview questions that use array data structure:
- Find a pair with the given sum in an array
- Check if a subarray with 0 sum exists or not
- Print all subarrays with 0 sum
- Sort binary array in linear time
- Find maximum length subarray having a given sum
- Find maximum length subarray having an equal number of 0’s and 1’s
- Find the maximum product of two integers in an array
- Sort an array of 0’s, 1’s, and 2’s (Dutch National Flag Problem)
- In-place merge two sorted arrays
- Merge two arrays by satisfying given constraints
- Find the index of 0 to be replaced to get the maximum length sequence of continuous ones
- Shuffle an array using Fisher–Yates shuffle algorithm
- Rearrange an array with alternate high and low elements
- Find equilibrium index of an array
- Find the largest subarray formed by consecutive integers
- Find majority element (Boyer–Moore Majority Vote Algorithm)
- Move all zeros present in an array to the end
- Replace every array element with the product of every other element
- Longest Bitonic Subarray Problem
- Find the maximum difference between two array elements that satisfies the given constraints
- Print continuous subarray with maximum sum
- Maximum Sum Circular Subarray
- Find all distinct combinations of a given length — I
- Find the maximum sequence of continuous 1’s formed by replacing at-most `k` zeroes by ones
- Find minimum sum subarray of size `k`
- Maximum Product Subarray Problem
- Find a subarray having the given sum in an integer array
- Find the smallest subarray length whose sum of elements is greater than `k`
- Find the smallest window in an array sorting which will make the entire array sorted
- Find maximum sum path involving elements of given arrays
- Find maximum profit earned by buying and selling shares any number of times
- Trapping Rain Water Problem
- Find minimum platforms needed to avoid delay in the train arrival
- Decode an array constructed from another array
- Sort an array in one swap whose two elements are swapped
- Find a triplet with the given sum in an array
- Find the length of the longest continuous sequence with the same sum in given binary arrays
- Reverse every consecutive `m`-elements of a subarray
- Maximum Product Subset Problem
- Find pairs with difference `k` in an array
- 4–Sum Problem | Quadruplets with a given sum
- Print all quadruplets with a given sum | 4 sum problem extended
- Quickselect Algorithm
- Rearrange array such that `A[A[i]]` is set to `i` for every element `A[i]`
- Print all triplets that form an arithmetic progression
- Print all triplets that form a geometric progression
- Group elements of an array based on their first occurrence
- Find the minimum difference between the index of two given elements present in an array
- Find the maximum absolute difference between the sum of two non-overlapping subarrays
- Find all symmetric pairs in an array of pairs
- Find the closest pair to a given sum in two sorted arrays
- Partition an array into two subarrays with the same sum
- Find the count of distinct elements in every subarray of size `k`
- Find two numbers with maximum sum formed by array digits
- Print all subarrays of an array having distinct elements
- Find a triplet having the maximum product in an array
- Find the minimum index of a repeating element in an array
- Find a pair with a minimum absolute sum in an array
- Find an index of the maximum occurring element with equal probability
- Check if an array is formed by consecutive integers
- Find two non-overlapping pairs having the same sum in an array
- Add elements of two arrays into a new array
- Find minimum product among all combinations of triplets in an array
- Count distinct absolute values in a sorted array
- Print all combinations of positive integers in increasing order that sums to a given number
- Find all distinct combinations of a given length — II
- Find subarrays with a given sum in an array
- Find maximum length sequence of continuous ones (Using Sliding Window)
- Find maximum length sequence of continuous ones
- Find the index that divides an array into two non-empty subarrays with equal sum
- Efficiently calculate the frequency of all elements present in a limited range array
- Rearrange an array such that it contains positive and negative numbers at alternate positions
- Find the sorted triplet in an array
- Shuffle an array according to the given order of elements
- Count the number of strictly increasing subarrays in an array
- Find duplicates within a range `k` in an array
- Find a minimum range with at least one element from each of the given arrays
- Find the longest subsequence formed by consecutive integers
- Determine the index of an element that satisfies given constraints in an array
- Find minimum moves required for converting a given array to an array of zeroes
- Left rotate an array
- Right rotate an array `k` times
- Activity Selection Problem
- Job Sequencing Problem with Deadlines
- 3–partition problem extended | Printing all partitions
- Count triplets which form an inversion in an array
- Determine whether an array can be divided into pairs with a sum divisible by `k`
- Find minimum removals required in an array to satisfy given constraints
- Find a pair with the given sum in a circularly sorted array
- Segregate positive and negative integers in linear time
- Find the minimum and maximum element in an array using minimum comparisons
- Insertion Sort Algorithm
- Selection Sort Algorithm
- Bubble Sort Algorithm
- Merge Sort Algorithm
- Iterative Merge Sort Algorithm (Bottom-up Merge Sort)
- Quicksort Algorithm
- Hybrid QuickSort Algorithm
- Quicksort using Dutch National Flag Algorithm
- Quicksort algorithm using Hoare’s partitioning scheme
- Counting Sort Algorithm
- Heap Sort Algorithm
- Introsort Algorithm — Overview and C++ Implementation
- External Merge Sort Algorithm
- Inversion count of an array
- Problems solved using partitioning logic of Quicksort
- Sort elements by their frequency and index
- Sort an array based on order defined by another array
- Efficiently sort an array with many duplicated values
- Find the largest number possible from a given set of numbers
- Find surpasser count for each array element
- Segregate positive and negative integers using merge sort
- Water Jugs Problem
- Sort an array using Young tableau
- Find all combinations of elements satisfying given constraints
- K–Partition Problem | Printing all partitions
- Find all distinct combinations of a given length with repetition allowed
- Print all combinations of numbers from 1 to `n` having sum `n`
- Print all triplets in an array with a sum less than or equal to a given number
- Difference between Subarray, Subsequence, and Subset
- Print all distinct subsets of a given set
- Find the missing number in an array
- Find the missing number in an array without using any extra space
- Find the odd occurring element in an array in a single traversal
- Find two odd occurring elements in an array without using any extra space
- Find all odd occurring elements in an array having a limited range of elements
- Find the duplicate element in a limited range array
- Find two duplicate elements in a limited range array (using XOR)
- Find the missing number and duplicate elements in an array
- Merging Overlapping Intervals
- Maximum Overlapping Intervals Problem
- Find the next greater element for every element in a circular array
- Find the next greater element for every array element
- Find the previous smaller element for each array element
- Reverse an array in C++
- Longest Increasing Subsequence Problem
- Find all elements in an array that are greater than all elements to their right
- Iterative Implementation of Quicksort
- Combinations of words formed by replacing given numbers with corresponding alphabets
- Replace every array element with the least greater element on its right
- Print complete Binary Search Tree (BST) in increasing order
- Binary Search Algorithm
- Find the number of rotations in a circularly sorted array
- Search an element in a circularly sorted array
- Find the first or last occurrence of a given number in a sorted array
- Count occurrences of a number in a sorted array with duplicates
- Find the smallest missing element from a sorted array
- Find floor and ceil of a number in a sorted integer array
- Search in a nearly sorted array in logarithmic time
- Find the number of 1’s in a sorted binary array
- Find the peak element in an array
- Maximum Subarray Sum using Divide and Conquer
- Find the missing term in a sequence in logarithmic time
- Find floor and ceil of a number in a sorted array (Recursive solution)
- Find the frequency of each element in a sorted array containing duplicates
- Find the odd occurring element in an array in logarithmic time
- Find pairs with difference `k` in an array | Constant Space Solution
- Find `k` closest elements to a given value in an array
- Find the minimum and maximum element in an array using Divide and Conquer
- Binary Search in C++ STL and Java Collections
- Ternary Search vs Binary search
- Exponential search
- Interpolation search
- Longest Increasing Subsequence using Dynamic Programming
- Longest Decreasing Subsequence Problem
- Longest Bitonic Subsequence
- Maximum Sum Increasing Subsequence Problem
- Matrix Chain Multiplication using Dynamic Programming
- 0–1 Knapsack Problem
- Maximize the value of an expression
- Partition Problem using Dynamic Programming
- Subset Sum Problem — Dynamic Programming Solution
- 3–Partition Problem
- Minimum Sum Partition Problem
- Rod Cutting Problem
- Coin change-making problem
- Coin Change Problem
- Longest Alternating Subsequence Problem
- Weighted Interval Scheduling Problem
- Box Stacking Problem
- Activity Selection Problem using Dynamic Programming
- Weighted Interval Scheduling — Dynamic Programming Solution
- Find minimum jumps required to reach the destination
- Find maximum profit earned from at most `k` stock transactions
- Find the maximum sum of a subsequence with no adjacent elements
- Minimum-weight triangulation of a convex polygon
- Find maximum profit that can be earned by conditionally selling stocks
- Truncate an integer array such that `2×min` becomes more than `max`
- Maximum Sum Subarray Problem (Kadane’s Algorithm)
- Longest Alternating Subarray Problem
- Find maximum profit earned from at most two stock transactions
- Find ways to calculate a target from elements of the specified array
- Find itinerary from the given list of departure and arrival airports
- Introduction to Priority Queues using Binary Heaps
- Check if an array represents a min-heap or not
- Convert max heap to min heap in linear time
- Find k’th largest element in an array
- Sort a k-sorted array
- Merge `M` sorted lists of variable length
- Find k’th smallest element in an array
- Find the smallest range with at least one element from each of the given lists
- Merge `M` sorted lists each containing `N` elements
- Connect `n` ropes with minimal cost
- Replace each array element by its corresponding rank
- Generate the power set of a given set
- Set both elements of a binary array to 0 in a single line
- Generate random input from an array according to given probabilities
Thanks for reading.