Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
What is a Subarray?
For example, Consider the array [1, 2, 3, 4], There are 10 non-empty sub-arrays. The
subarrays are:
(1), (2), (3), (4), (1,2), (2,3), (3,4), (1,2,3), (2,3,4), and (1,2,3,4)
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 1/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
Subarray
What is a Subsequence?
More generally, we can say that for a sequence of size n, we can have (2n – 1) non-empty sub-
sequences in total.
For the same above example, there are 15 sub-sequences. They are:
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 2/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
(1), (2), (3), (4), (1,2), (1,3),(1,4), (2,3), (2,4), (3,4), (1,2,3), (1,2,4), (1,3,4), (2,3,4),
(1,2,3,4).
Subsequences
What is a Subset?
If a Set has all its elements belonging to other sets, this set will be known as a subset of
the other set.
Then, A ⊆ B.
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 3/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
Subset
Table of Content
What is a Subarray?
What is a Subsequence?
What is a Subset?
Easy Problems on Subarray
Medium Problems on Subarray
Hard Problems on Subarray
Easy Problems on Subsequence
Medium Problems on Subsequence
Hard Problems on Subsequence
Easy Problems on Subset
Medium Problems on Subset
Hard Problems on Subset
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 4/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
Maximum length of the sub-array whose first and last elements are same
Check whether an Array is Subarray of another Array
Find array such that no subarray has xor zero or Y
Maximum subsequence sum such that all elements are K distance apart
Longest sub-array with maximum GCD
Count of subarrays with sum at least K
Length of Smallest subarray in range 1 to N with sum greater than a given value
Sum of all subarrays of size K
Split array into K disjoint subarrays such that sum of each subarray is odd.
Find an array of size N having exactly K subarrays with sum S
Find the subarray of size K with minimum XOR
Length of the longest alternating even odd subarray
Count of subarrays which start and end with the same element
Count of subarrays having exactly K perfect square numbers
Split array into two subarrays such that difference of their maximum is minimum
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 5/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 6/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 7/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 8/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 9/10
5/9/24, 12:34 PM Subarrays, Subsequences, and Subsets in Array - GeeksforGeeks
Sum of all subsets whose sum is a Perfect Number from a given array
Minimize sum of incompatibilities of K equal-length subsets made up of unique elements
Maximize sum of subsets from two arrays having no consecutive values
Product of the maximums of all subsets of an array
Count ways to place ‘+’ and ‘-‘ in front of array elements to obtain sum K
Count ways to split array into two subsets having difference between their sum equal to K
Find the subset of Array with given LCM
Count of subsets whose product is multiple of unique primes
Minimum count of elements to be inserted in Array to form all values in [1, K] using
subset sum
Maximum subset sum having difference between its maximum and minimum in range [L,
R]
Find all unique subsets of a given set using C++ STL
Subset sum problem where Array sum is at most N
Related Articles:
https://www.geeksforgeeks.org/array-subarray-subsequence-and-subset/?ref=lbp 10/10