You are on page 1of 2

Courses Tutorials Jobs Practice Contests Sign In

DSA Data Structures Algorithms Interview Preparation Data Science Topic-wise Practice C C++ Java Python Latest Blogs Competitive Programming JavaScript Machine Learning Write & Earn Web Development Puzzles Projects

Write an Article
Courses
Write an Interview Experience
Subarrays, Subsequences, and Subsets in Array
Last Updated : 15 Sep, 2022
Array Data Structure

What is Array? Read Discuss Courses Practice Video


115k+ interested Geeks 98k+ in

Introduction to Arrays – Data Structure and Master Java Programming Master C


What is a Subarray?
Algorithm Tutorials - Complete Beginner to… - Comple
Beginner to Advance Beginn
Applications, Advantages and Disadvantages of
Array A subarray is a contiguous par t of array, i.e., Subarray is an array that is inside another array.

Subarrays, Subsequences, and Subsets in Array


In general, for an array of size n, there are n*(n+1)/2 non-empty subarrays.

Basic operations in Array


For example, Consider the array [1, 2, 3, 4], There are 10 non-empty sub-arrays. The subarrays are:

Easy problems on Array


(1), (2), (3), (4),
(1,2), (2,3), (3,4),
Intermediate problems on Array
(1,2,3), (2,3,4), and
(1,2,3,4)
Hard problems on Array

What is a Subsequence?

A subsequence is a sequence that can be derived from another sequence by removing zero or more elements, without changing

the order of the remaining elements.

n
More generally, we can say that for a sequence of size n, we can have (2 – 1) non-empty sub-sequences in total.

For the same above example, there are 15 sub-sequences. They are:

(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).

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.

A Subset is denoted as “ ⊆“. If set A is a subset of set B, it is represented as A ⊆ B.

For example, Let Set_A = {m, n, o, p, q}, Set_ B = {k, l, m, n, o, p, q, r}

Then, A ⊆ B.

Topic s :

     
What is Subarray What is Subsequence What is Subset

Coding Problems on Subarray Coding Problems on Subsequence Coding Problems on Subset

Easy Problems on Subarray Easy Problems on Subsequence Easy Problems on Subset

Intermediate Problems on Intermediate Problems on Intermediate Problems on Subset

Subarray Subsequence Hard Problems on Subset

Hard Problems on Subarray Hard Problems on Subsequence Recent ar ticles on Subset

Recent ar ticles on Subarray Recent ar ticles on Subsequence

Problems on Subarray:

Easy Problems on Subarray:

1. Split an array into two equal Sum subarrays

2. Check if subarray with given product exist s in an array

3. Subarray of size k with given sum

4. Sor t an array where a subarray of a sor ted array is in reverse order

5. Count subarrays with all element s greater than K

6. Maximum length of the sub-array whose first and last element s are same

7. Check whether an Array is Subarray of another Array

8. Find array such that no subarray has xor zero or Y

9. Maximum subsequence sum such that all element s are K distance apar t

10. Longest sub-array with maximum GCD

11. Count of subarrays with sum at least K

12. Length of Smallest subarray in range 1 to N with sum greater than a given value

13. Sum of all subarrays of size K

14. Split array into K disjoint subarrays such that sum of each subarray is odd.

15. Find an array of size N having exactly K subarrays with sum S

16. Find the subarray of size K with minimum XOR

17. Length of the longest alternating even odd subarray

18. Count of subarrays which star t and end with the same element

19. Count of subarrays having exactly K per fect square numbers

20. Split array into two subarrays such that dif ference of their maximum is minimum

Intermediate problems on Subarray:

1. Print all K digit repeating numbers in a ver y large number

2. Length of longest subarray whose sum is not divisible by integer K

3. Min dif ference between maximum and minimum element in all Y size subarrays

4. Longest subarray of non-empty cells af ter removal of at most a single empty cell

5. First subarray with negative sum from the given Array

6. L argest subarray with frequency of all element s same

7. Bitwise operations on Subarrays of size K

8. Count subarrays having sum of element s at even and odd positions equal

9. Longest Subarray consisting of unique element s from an Array

10. Minimum Decrement s on Subarrays required to reduce all Array element s to zero

11. Split array into two subarrays such that dif ference of their sum is minimum

12. Maximize count of non-overlapping subarrays with sum K

13. Smallest subarray which upon repetition gives the original array

14. Split array into maximum subarrays such that ever y distinct element lies in a single subarray

15. Maximize product of subarray sum with it s minimum element

16. Sum of product s of all possible Subarrays

17. Check if all subarrays contains at least one unique element

18. Length of smallest subarray to be removed such that the remaining array is sor ted

19. Length of longest subarray having frequency of ever y element equal to K

20. Length of the longest increasing subsequence which does not contain a given sequence as Subarray

Hard Problems on Subarray:

1. Length of smallest subarray to be removed to make sum of remaining element s divisible by K

2. Maximum length of same indexed subarrays from two given arrays satisf ying the given condition

3. Count ways to split array into two equal sum subarrays by changing sign of any one array element

4. Longest subarray in which all element s are smaller than K

5. Maximize product of a strictly increasing or decreasing subarray

6. Sum of maximum of all subarrays by adding even frequent maximum twice

7. Longest subarray of an array which is a subsequence in another array

8. Count of subarrays having product as a per fect cube

9. Minimize dif ference between maximum and minimum array element s by removing a K-length subarray

10. Maximum sum submatrix

11. Minimum removal of element s from end of an array required to obtain sum K

12. Check if any subarray of length M repeat s at least K times consecutively or not

13. Minimize flips on K-length subarrays required to make all array element s equal to 1

14. Split array into K subarrays such that sum of maximum of all subarrays is maximized

15. Find minimum subarray sum for each index i in subarray [i, N-1]

16. Longest subarray with GCD greater than 1

17. Longest subsegment of ‘1’s formed by changing at most k ‘0’s

18. Lexicographically smallest Permutation of Array by reversing at most one Subarray

19. Find a subsequence which upon reversing gives the maximum sum subarray

20. Minimize steps to make Array element s 0 by reducing same A[i] – X from Subarray

Problems on Subsequence:

Easy Problems on Subsequence :

1. Longest subsequence having equal numbers of 0 and 1

2. Powers of two and subsequences

3. Longest Subsequence where index of next element is arr[arr[i] + i]

4. Number of subsequences with zero sum

5. Longest sub-sequence with maximum GCD

6. Maximum Bitwise AND value of subsequence of length K

7. Length of the longest subsequence such that xor of adjacent element s is non-decreasing

8. Maximum product of bitonic subsequence of size 3

9. Length of Smallest Subsequence such that sum of element s is greater than equal to K

10. Longest subsequence of even numbers in an Array

11. Maximum length Subsequence with alternating sign and maximum Sum

12. Count of possible subarrays and subsequences using given length of Array

13. Maximum bitwise OR value of subsequence of length K

14. Count of subsequences consisting of the same element

15. Smallest occurring element in each subsequence

16. Length of the longest subsequence consisting of distinct element s

17. Minimize element s to be added to a given array such that it contains another given array as it s subsequence

18. Maximize subsequences having array element s not exceeding length of the subsequence

19. Length of longest subsequence consisting of distinct adjacent element s

20. Maximum Sum Subsequence

Intermediate Problems on Subsequence :

1. Minimum removals required to make a given array Bitonic

2. Check if a non-contiguous subsequence same as the given subarray exist s or not

3. Minimize the number of strictly increasing subsequences in an array

4. Count of unique subsequences from given number which are power of 2

5. Minimum number of inser tions required such that first K natural numbers can be obtained as sum of a subsequence of the

array

6. Length of longest subsequence such that prefix sum at ever y element remains greater than zero

7. Check if given Array can be divided into subsequences of K increasing consecutive integers

8. Longest Subsequence such that dif ference between adjacent element s is either A or B

9. Count subsequences of Array having single digit integer sum K

10. Shor test Subsequence with sum exactly K

11. Printing Longest Bitonic Subsequence

12. Sor ted subsequence of size 3 in linear time using constant space

13. Count of subsequences having maximum distinct element s

14. Construct array having X subsequences with maximum dif ference smaller than d

15. Print all subsequences of a string using ArrayList

16. Longest Subsequence with at least one common digit in ever y element

17. Maximum Sum Subsequence of length k

18. Sum of minimum element of all sub-sequences of a sor ted array

19. Find all combinations of two equal sum subsequences

20. Minimum cost of choosing 3 increasing element s in an array of size N

Hard Problems on Subsequence :

1. Number of subsequences with positive product

2. Longest subsequence having dif ference atmost K

3. Find all subsequences with sum equals to K

4. Maximize product of digit sum of consecutive pairs in a subsequence of length K

5. Count of subsequences of length atmost K containing distinct prime element s

6. Sum of all subsequences of length K

7. Minimize sum of smallest element s from K subsequences of length L

8. Unique subsequences of length K with given sum

9. Smallest subsequence with sum of absolute dif ference of consecutive element s maximized

10. Maximize product of same-indexed element s of same size subsequences

11. Longest Increasing Subsequence having sum value atmost K

12. Longest subsequence of a number having same lef t and right rotation

13. Maximize length of Non-Decreasing Subsequence by reversing at most one Subarray

14. Maximum subsequence sum possible by multiplying each element by it s index

15. Generate all distinct subsequences of array using back tracking

16. Maximum subsequence sum such that no K element s are consecutive

17. Print all possible K-length subsequences of first N natural numbers with sum N

18. Longest subsequence having dif ference between the maximum and minimum element equal to K

19. Maximize dif ference between sum of even and odd-indexed element s of a subsequence

20. Conver t an array into another by repeatedly removing the last element and placing it at any arbitrar y index

Problems on Subset:

Easy Problems on Subset :

1. Find if there is any subset of size K with 0 sum in an array of -1 and +1

2. Sum of sum of all subset s of a set formed by first N natural numbers

3. Count of subset s not containing adjacent element s

4. Sum of the sums of all possible subset s

5. Find whether an array is subset of another array

6. Total number of Subset s of size at most K

7. Check if it is possible to split given Array into K odd-sum subset s

8. Par tition a set into two subset s such that dif ference between max of one and min of other is minimized

9. Sum of all possible expressions of a numeric string possible by inser ting addition operators

10. Check if it ’s possible to split the Array into strictly increasing subset s of size at least K

11. L argest subset of Array having sum at least 0

Intermediate Problems on Subset :

1. Number of subset s with sum divisible by m

2. Fibonacci sum of a subset with all element s <= k

3. Number of possible Equivalence Relations on a finite set

4. L argest divisible pairs subset

5. Recursive program to print all subset s with given sum

6. Subset Sum Queries in a Range using Bit set

7. Find all distinct subset (or subsequence) sums of an array | Set-2

8. Sum of (maximum element – minimum element) for all the subset s of an array

9. Count no. of ordered subset s having a par ticular XOR value

10. Sum of subset s of all the subset s of an array

11. Per fect Sum Problem

12. Count of subset s having sum of min and max element less than K

13. Split array into two equal length subset s such that all repetitions of a number lies in a single subset

14. Nth Subset of the Sequence consisting of powers of K in increasing order of their Sum

15. L argest possible Subset from an Array such that no element is K times any other element in the Subset

16. Check if an array can be split into subset s of K consecutive element s

Hard Problems on Subset :

1. Minimize count of divisions by D to obtain at least K equal array element s

2. Split array into K-length subset s to minimize sum of second smallest element of each subset

3. Median of all non-empty subset sums

4. Minimum removals required such that sum of remaining array modulo M is X

5. Sum of length of two smallest subset s possible from a given array with sum at least K

6. Reduce sum of any subset of an array to 1 by multiplying all it s element s by any value

7. Sum of all subset s whose sum is a Per fect Number from a given array

8. Minimize sum of incompatibilities of K equal-length subset s made up of unique element s

9. Maximize sum of subset s from two arrays having no consecutive values

10. Product of the maximums of all subset s of an array

11. Count ways to place ‘+’ and ‘-‘ in front of array element s to obtain sum K

12. Count ways to split array into two subset s having dif ference between their sum equal to K

13. Find the subset of Array with given LCM

14. Count of subset s whose product is multiple of unique primes

15. Minimum count of element s to be inser ted in Array to form all values in [1, K] using subset sum

16. Maximum subset sum having dif ference between it s maximum and minimum in range [L, R]

17. Find all unique subset s of a given set using C++ STL

18. Subset sum problem where Array sum is at most N

Data Struc ture and Algorithms Course

Recent articles on Subarray

Recent articles on Subsequence

Recent articles on Subset

Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above

Related Articles

1. Print BST from array of strings where every string contains leaf nodes removed in iteration

2. Array C/C++ Programs

3. Array | Searching

4. Array | Sorting

5. Array Rearrangement

6. Array | Range Queries

7. Array | Order Statistics

8. Numpy | Iterating Over Array

9. Numpy | Array Creation

10. Array Data Structure


Start Your Coding Journey Now! Login Register

Company Learn News Languages Web Development Contribute


Top News
A-143, 9th Floor, Sovereign Corporate Tower, About Us DSA Python Web Tutorials Write an Article
Sector-136, Noida, Uttar Pradesh - 201305 Technology
Careers Algorithms Java Django Tutorial Improve an Article
feedback@geeksforgeeks.org Work & Career
In Media Data Structures CPP HTML Pick Topics to Write
Business
Contact Us SDE Cheat Sheet Golang JavaScript Write Interview Experience
Finance
Privacy Policy Machine learning C# Bootstrap Internships
Lifestyle
Copyright Policy CS Subjects SQL ReactJS Video Internship
Knowledge
Advertise with us Video Tutorials Kotlin NodeJS
Courses

@geeksforgeeks , Some rights reserved

You might also like