Find whether an array is subset of another array | Added Method 3
Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order. It may be assumed that elements in both array are distinct.
Examples:
Input: arr1[] = {11, 1, 13, 21, 3, 7}, arr2[] = {11, 3, 7, 1}
Output: arr2[] is a subset of arr1[]
Input: arr1[] = {1, 2, 3, 4, 5, 6}, arr2[] = {1, 2, 4}
Output: arr2[] is a subset of arr1[]
Input: arr1[] = {10, 5, 2, 23, 19}, arr2[] = {19, 5, 3}
Output: arr2[] is not a subset of arr1[]
Method 1 (Simple)
Use two loops: The outer loop picks all the elements of arr2[] one by one. The inner loop linearly searches for the element picked by outer loop. If all elements are found then return 1, else return 0.
C++
// C++ program to find whether an array // is subset of another array #include<bits/stdc++.h> /* Return 1 if arr2[] is a subset of arr1[] */ bool isSubset( int arr1[], int arr2[], int m, int n) { int i = 0; int j = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (arr2[i] == arr1[j]) break ; } /* If the above inner loop was not broken at all then arr2[i] is not present in arr1[] */ if (j == m) return 0; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return 1; } // Driver code int main() { int arr1[] = {11, 1, 13, 21, 3, 7}; int arr2[] = {11, 3, 7, 1}; int m = sizeof (arr1)/ sizeof (arr1[0]); int n = sizeof (arr2)/ sizeof (arr2[0]); if (isSubset(arr1, arr2, m, n)) printf ( "arr2[] is subset of arr1[] " ); else printf ( "arr2[] is not a subset of arr1[]" ); getchar (); return 0; } |
Java
// Java program to find whether an array // is subset of another array class GFG { /* Return true if arr2[] is a subset of arr1[] */ static boolean isSubset( int arr1[], int arr2[], int m, int n) { int i = 0 ; int j = 0 ; for (i = 0 ; i < n; i++) { for (j = 0 ; j < m; j++) if (arr2[i] == arr1[j]) break ; /* If the above inner loop was not broken at all then arr2[i] is not present in arr1[] */ if (j == m) return false ; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return true ; } // Driver code public static void main(String args[]) { int arr1[] = { 11 , 1 , 13 , 21 , 3 , 7 }; int arr2[] = { 11 , 3 , 7 , 1 }; int m = arr1.length; int n = arr2.length; if (isSubset(arr1, arr2, m, n)) System.out.print( "arr2[] is " + "subset of arr1[] " ); else System.out.print( "arr2[] is " + "not a subset of arr1[]" ); } } |
Python 3
# Python 3 program to find whether an array # is subset of another array # Return 1 if arr2[] is a subset of # arr1[] def isSubset(arr1, arr2, m, n): i = 0 j = 0 for i in range (n): for j in range (m): if (arr2[i] = = arr1[j]): break # If the above inner loop was # not broken at all then arr2[i] # is not present in arr1[] if (j = = m): return 0 # If we reach here then all # elements of arr2[] are present # in arr1[] return 1 # Driver code if __name__ = = "__main__" : arr1 = [ 11 , 1 , 13 , 21 , 3 , 7 ] arr2 = [ 11 , 3 , 7 , 1 ] m = len (arr1) n = len (arr2) if (isSubset(arr1, arr2, m, n)): print ( "arr2[] is subset of arr1[] " ) else : print ( "arr2[] is not a subset of arr1[]" ) # This code is contributed by ita_c |
C#
// C# program to find whether an array // is subset of another array using System; class GFG { /* Return true if arr2[] is a subset of arr1[] */ static bool isSubset( int []arr1, int []arr2, int m, int n) { int i = 0; int j = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) if (arr2[i] == arr1[j]) break ; /* If the above inner loop was not broken at all then arr2[i] is not present in arr1[] */ if (j == m) return false ; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return true ; } // Driver function public static void Main() { int []arr1 = {11, 1, 13, 21, 3, 7}; int []arr2 = {11, 3, 7, 1}; int m = arr1.Length; int n = arr2.Length; if (isSubset(arr1, arr2, m, n)) Console.WriteLine( "arr2[] is subset" + " of arr1[] " ); else Console.WriteLine( "arr2[] is not a " + "subset of arr1[]" ); } } // This code is contributed by Sam007 |
PHP
<?php // PHP program to find whether an array // is subset of another array /* Return 1 if arr2[] is a subset of arr1[] */ function isSubset( $arr1 , $arr2 , $m , $n ) { $i = 0; $j = 0; for ( $i = 0; $i < $n ; $i ++) { for ( $j = 0; $j < $m ; $j ++) { if ( $arr2 [ $i ] == $arr1 [ $j ]) break ; } /* If the above inner loop was not broken at all then arr2[i] is not present in arr1[] */ if ( $j == $m ) return 0; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return 1; } // Driver code $arr1 = array (11, 1, 13, 21, 3, 7); $arr2 = array (11, 3, 7, 1); $m = count ( $arr1 ); $n = count ( $arr2 ); if (isSubset( $arr1 , $arr2 , $m , $n )) echo "arr2[] is subset of arr1[] " ; else echo "arr2[] is not a subset of arr1[]" ; // This code is contributed by anuj_67. ?> |
Output:
arr2[] is subset of arr1[]
Time Complexity: O(m*n)
Method 2 (Use Sorting and Binary Search)
1) Sort arr1[] O(mLogm) 2) For each element of arr2[], do binary search for it in sorted arr1[]. a) If the element is not found then return 0. 3) If all elements are present then return 1.
C++
// C++ program to find whether an array // is subset of another array #include<bits/stdc++.h> using namespace std; /* Fucntion prototypes */ void quickSort( int *arr, int si, int ei); int binarySearch( int arr[], int low, int high, int x); /* Return 1 if arr2[] is a subset of arr1[] */ bool isSubset( int arr1[], int arr2[], int m, int n) { int i = 0; quickSort(arr1, 0, m-1); for (i=0; i<n; i++) { if (binarySearch(arr1, 0, m - 1, arr2[i]) == -1) return 0; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return 1; } /* FOLLOWING FUNCTIONS ARE ONLY FOR SEARCHING AND SORTING PURPOSE */ /* Standard Binary Search function*/ int binarySearch( int arr[], int low, int high, int x) { if (high >= low) { int mid = (low + high)/2; /*low + (high - low)/2;*/ /* Check if arr[mid] is the first occurrence of x. arr[mid] is first occurrence if x is one of the following is true: (i) mid == 0 and arr[mid] == x (ii) arr[mid-1] < x and arr[mid] == x */ if (( mid == 0 || x > arr[mid-1]) && (arr[mid] == x)) return mid; else if (x > arr[mid]) return binarySearch(arr, (mid + 1), high, x); else return binarySearch(arr, low, (mid -1), x); } return -1; } void exchange( int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } int partition( int A[], int si, int ei) { int x = A[ei]; int i = (si - 1); int j; for (j = si; j <= ei - 1; j++) { if (A[j] <= x) { i++; exchange(&A[i], &A[j]); } } exchange (&A[i + 1], &A[ei]); return (i + 1); } /* Implementation of Quick Sort A[] --> Array to be sorted si --> Starting index ei --> Ending index */ void quickSort( int A[], int si, int ei) { int pi; /* Partitioning index */ if (si < ei) { pi = partition(A, si, ei); quickSort(A, si, pi - 1); quickSort(A, pi + 1, ei); } } /*Driver code */ int main() { int arr1[] = {11, 1, 13, 21, 3, 7}; int arr2[] = {11, 3, 7, 1}; int m = sizeof (arr1) / sizeof (arr1[0]); int n = sizeof (arr2) / sizeof (arr2[0]); if (isSubset(arr1, arr2, m, n)) cout << "arr2[] is subset of arr1[] " ; else cout << "arr2[] is not a subset of arr1[] " ; return 0; } // This code is contributed by Shivi_Aggarwal |
C
// C program to find whether an array // is subset of another array #include<stdio.h> /* Fucntion prototypes */ void quickSort( int *arr, int si, int ei); int binarySearch( int arr[], int low, int high, int x); /* Return 1 if arr2[] is a subset of arr1[] */ bool isSubset( int arr1[], int arr2[], int m, int n) { int i = 0; quickSort(arr1, 0, m-1); for (i=0; i<n; i++) { if (binarySearch(arr1, 0, m-1, arr2[i]) == -1) return 0; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return 1; } /* FOLLOWING FUNCTIONS ARE ONLY FOR SEARCHING AND SORTING PURPOSE */ /* Standard Binary Search function*/ int binarySearch( int arr[], int low, int high, int x) { if (high >= low) { int mid = (low + high)/2; /*low + (high - low)/2;*/ /* Check if arr[mid] is the first occurrence of x. arr[mid] is first occurrence if x is one of the following is true: (i) mid == 0 and arr[mid] == x (ii) arr[mid-1] < x and arr[mid] == x */ if (( mid == 0 || x > arr[mid-1]) && (arr[mid] == x)) return mid; else if (x > arr[mid]) return binarySearch(arr, (mid + 1), high, x); else return binarySearch(arr, low, (mid -1), x); } return -1; } void exchange( int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } int partition( int A[], int si, int ei) { int x = A[ei]; int i = (si - 1); int j; for (j = si; j <= ei - 1; j++) { if (A[j] <= x) { i++; exchange(&A[i], &A[j]); } } exchange (&A[i + 1], &A[ei]); return (i + 1); } /* Implementation of Quick Sort A[] --> Array to be sorted si --> Starting index ei --> Ending index */ void quickSort( int A[], int si, int ei) { int pi; /* Partitioning index */ if (si < ei) { pi = partition(A, si, ei); quickSort(A, si, pi - 1); quickSort(A, pi + 1, ei); } } /*Driver program to test above functions */ int main() { int arr1[] = {11, 1, 13, 21, 3, 7}; int arr2[] = {11, 3, 7, 1}; int m = sizeof (arr1)/ sizeof (arr1[0]); int n = sizeof (arr2)/ sizeof (arr2[0]); if (isSubset(arr1, arr2, m, n)) printf ( "arr2[] is subset of arr1[] " ); else printf ( "arr2[] is not a subset of arr1[] " ); return 0; } |
Java
// Java program to find whether an array // is subset of another array class Main { /* Return true if arr2[] is a subset of arr1[] */ static boolean isSubset( int arr1[], int arr2[], int m, int n) { int i = 0 ; sort(arr1, 0 , m- 1 ); for (i= 0 ; i<n; i++) { if (binarySearch(arr1, 0 , m- 1 , arr2[i]) == - 1 ) return false ; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return true ; } /* FOLLOWING FUNCTIONS ARE ONLY FOR SEARCHING AND SORTING PURPOSE */ /* Standard Binary Search function*/ static int binarySearch( int arr[], int low, int high, int x) { if (high >= low) { int mid = (low + high)/ 2 ; /*low + (high - low)/2;*/ /* Check if arr[mid] is the first occurrence of x. arr[mid] is first occurrence if x is one of the following is true: (i) mid == 0 and arr[mid] == x (ii) arr[mid-1] < x and arr[mid] == x */ if (( mid == 0 || x > arr[mid- 1 ]) && (arr[mid] == x)) return mid; else if (x > arr[mid]) return binarySearch(arr, (mid + 1 ), high, x); else return binarySearch(arr, low, (mid - 1 ), x); } return - 1 ; } /* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */ static int partition( int arr[], int low, int high) { int pivot = arr[high]; int i = (low- 1 ); // index of smaller element for ( int j=low; j<high; j++) { // If current element is smaller than or // equal to pivot if (arr[j] <= pivot) { i++; // swap arr[i] and arr[j] int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) int temp = arr[i+ 1 ]; arr[i+ 1 ] = arr[high]; arr[high] = temp; return i+ 1 ; } /* The main function that implements QuickSort() arr[] --> Array to be sorted, low --> Starting index, high --> Ending index */ static void sort( int arr[], int low, int high) { if (low < high) { /* pi is partitioning index, arr[pi] is now at right place */ int pi = partition(arr, low, high); // Recursively sort elements before // partition and after partition sort(arr, low, pi- 1 ); sort(arr, pi+ 1 , high); } } public static void main(String args[]) { int arr1[] = { 11 , 1 , 13 , 21 , 3 , 7 }; int arr2[] = { 11 , 3 , 7 , 1 }; int m = arr1.length; int n = arr2.length; if (isSubset(arr1, arr2, m, n)) System.out.print( "arr2[] is subset of arr1[] " ); else System.out.print( "arr2[] is not a subset of arr1[]" ); } } |
C#
// C# program to find whether an array // is subset of another array using System; public class GFG { /* Return true if arr2[] is a subset of arr1[] */ static bool isSubset( int []arr1, int []arr2, int m, int n) { int i = 0; Array.Sort(arr1, 0, m-1); for (i=0; i<n; i++) { if (binarySearch(arr1, 0, m-1, arr2[i]) == -1) return false ; } /* If we reach here then all elements of arr2[] are present in arr1[] */ return true ; } /* FOLLOWING FUNCTIONS ARE ONLY FOR SEARCHING AND SORTING PURPOSE */ /* Standard Binary Search function*/ static int binarySearch( int []arr, int low, int high, int x) { if (high >= low) { int mid = (low + high)/2; /*low + (high - low)/2;*/ /* Check if arr[mid] is the first occurrence of x. arr[mid] is first occurrence if x is one of the following is true: (i) mid == 0 and arr[mid] == x (ii) arr[mid-1] < x and arr[mid] == x */ if (( mid == 0 || x > arr[mid-1]) && (arr[mid] == x)) return mid; else if (x > arr[mid]) return binarySearch(arr, (mid + 1), high, x); else return binarySearch(arr, low, (mid -1), x); } return -1; } /* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */ static int partition( int []arr, int low, int high) { int pivot = arr[high]; int i = (low-1); // index of smaller element int temp=0; for ( int j=low; j<high; j++) { // If current element is smaller than or // equal to pivot if (arr[j] <= pivot) { i++; // swap arr[i] and arr[j] temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // swap arr[i+1] and arr[high] (or pivot) temp = arr[i+1]; arr[i+1] = arr[high]; arr[high] = temp; return i+1; } /* The main function that implements QuickSort() arr[] --> Array to be sorted, low --> Starting index, high --> Ending index */ static void sort( int []arr, int low, int high) { if (low < high) { /* pi is partitioning index, arr[pi] is now at right place */ int pi = partition(arr, low, high); // Recursively sort elements before // partition and after partition sort(arr, low, pi-1); sort(arr, pi+1, high); } } public static void Main() { int []arr1 = {11, 1, 13, 21, 3, 7}; int []arr2= {11, 3, 7, 1}; int m = arr1.Length; int n = arr2.Length; if (isSubset(arr1, arr2, m, n)) Console.Write( "arr2[] is subset of arr1[] " ); else Console.Write( "arr2[] is not a subset of arr1[]" ); } } //This code is contributed by 29AjayKumar |
Output:
arr2 is a subset of arr1
Time Complexity: O(mLogm + nLogm). Please note that this will be the complexity if an mLogm algorithm is used for sorting which is not the case in above code. In above code Quick Sort is sued and worst case time complexity of Quick Sort is O(m^2)
Method 3 (Use Sorting and Merging )
1) Sort both arrays: arr1[] and arr2[] O(mLogm + nLogn)
2) Use Merge type of process to see if all elements of sorted arr2[] are present in sorted arr1[].
Thanks to Parthsarthi for suggesting this method.
C++
// C++ program to find whether an array // is subset of another array #include <bits/stdc++.h> using namespace std; /* Return 1 if arr2[] is a subset of arr1[] */ bool isSubset( int arr1[], int arr2[], int m, int n) { int i = 0, j = 0; if (m < n) return 0; sort(arr1, arr1 + m); sort(arr2, arr2 + n); while (i < n && j < m ) { if ( arr1[j] <arr2[i] ) j++; else if ( arr1[j] == arr2[i] ) { j++; i++; } else if ( arr1[j] > arr2[i] ) return 0; } return (i < n)? false : true ; } /*Driver program to test above functions */ int main() { int arr1[] = {11, 1, 13, 21, 3, 7}; int arr2[] = {11, 3, 7, 1}; int m = sizeof (arr1)/ sizeof (arr1[0]); int n = sizeof (arr2)/ sizeof (arr2[0]); if (isSubset(arr1, arr2, m, n)) printf ( "arr2[] is subset of arr1[] " ); else printf ( "arr2[] is not a subset of arr1[] " ); return 0; } |
Java
// Java code to find whether an array is subset of // another array import java.util.Arrays; class GFG { /* Return true if arr2[] is a subset of arr1[] */ static boolean isSubset( int arr1[], int arr2[], int m, int n) { int i = 0 , j = 0 ; if (m < n) return false ; Arrays.sort(arr1); //sorts arr1 Arrays.sort(arr2); // sorts arr2 while ( i < n && j < m ) { if ( arr1[j] < arr2[i] ) j++; else if ( arr1[j] == arr2[i] ) { j++; i++; } else if ( arr1[j] > arr2[i] ) return false ; } if ( i < n ) return false ; else return true ; } public static void main(String[] args) { int arr1[] = { 11 , 1 , 13 , 21 , 3 , 7 }; int arr2[] = { 11 , 3 , 7 , 1 }; int m = arr1.length; int n = arr2.length; if (isSubset(arr1, arr2, m, n)) System.out.println( "arr2 is a subset of arr1" ); else System.out.println( "arr2 is not a subset of arr1" ); } } // This code is contributed by Kamal Rawal |
Python3
# Python3 program to find whether an array # is subset of another array # Return 1 if arr2[] is a subset of arr1[] */ def isSubset(arr1, arr2, m, n): i = 0 j = 0 if m < n: return 0 arr1.sort() arr2.sort() while i < n and j < m: if arr1[j] < arr2[i]: j + = 1 elif arr1[j] = = arr2[i]: j + = 1 i + = 1 elif arr1[j] > arr2[i]: return 0 return False if i < n else True # Driver code arr1 = [ 11 , 1 , 13 , 21 , 3 , 7 ] arr2 = [ 11 , 3 , 7 , 1 ] m = len (arr1) n = len (arr2) if isSubset(arr1, arr2, m, n) = = True : print ( "arr2 is subset of arr1 " ) else : printf( "arr2 is not a subset of arr1 " ) # This code is contributed by Shrikant13 |
C#
// C# code to find whether an array // is subset of another array using System; class GFG { // Return true if arr2[] is // a subset of arr1[] */ static bool isSubset( int []arr1, int []arr2, int m, int n) { int i = 0, j = 0; if (m < n) return false ; //sorts arr1 Array.Sort(arr1); // sorts arr2 Array.Sort(arr2); while ( i < n && j < m ) { if ( arr1[j] < arr2[i] ) j++; else if ( arr1[j] == arr2[i] ) { j++; i++; } else if ( arr1[j] > arr2[i] ) return false ; } if ( i < n ) return false ; else return true ; } // Driver Code public static void Main() { int []arr1 = {11, 1, 13, 21, 3, 7}; int []arr2 = {11, 3, 7, 1}; int m = arr1.Length; int n = arr2.Length; if (isSubset(arr1, arr2, m, n)) Console.Write( "arr2 is a subset of arr1" ); else Console.Write( "arr2 is not a subset of arr1" ); } } // This code is contributed by nitin mittal. |
PHP
<?php // PHP program to find whether an array // is subset of another array /* Return 1 if arr2[] is a subset of arr1[] */ function isSubset( $arr1 , $arr2 , $m , $n ) { $i = 0; $j = 0; if ( $m < $n ) return 0; sort( $arr1 ); sort( $arr2 ); while ( $i < $n and $j < $m ) { if ( $arr1 [ $j ] < $arr2 [ $i ] ) $j ++; else if ( $arr1 [ $j ] == $arr2 [ $i ] ) { $j ++; $i ++; } else if ( $arr1 [ $j ] > $arr2 [ $i ] ) return 0; } return ( $i < $n ) ? false : true; } /*Driver program to test above functions */ $arr1 = array (11, 1, 13, 21, 3, 7); $arr2 = array (11, 3, 7, 1); $m = count ( $arr1 ); $n = count ( $arr2 ); if (isSubset( $arr1 , $arr2 , $m , $n )) echo "arr2[] is subset of arr1[] " ; else echo "arr2[] is not a subset of arr1[] " ; // This code is contributed by anuj_67. ?> |
Output:
arr2 is a subset of arr1
Time Complexity: O(mLogm + nLogn) which is better than method 2. Please note that this will be the complexity if an nLogn algorithm is used for sorting both arrays which is not the case in above code. In above code Quick Sort is sued and worst case time complexity of Quick Sort is O(n^2)
Method 4 (Use Hashing)
1) Create a Hash Table for all the elements of arr1[].
2) Traverse arr2[] and search for each element of arr2[] in the Hash Table. If element is not found then return 0.
3) If all elements are found then return 1.
Java
// Java code to find whether an array is subset of // another array import java.util.HashSet; class GFG { /* Return true if arr2[] is a subset of arr1[] */ static boolean isSubset( int arr1[], int arr2[], int m, int n) { HashSet<Integer> hset= new HashSet<>(); // hset stores all the values of arr1 for ( int i = 0 ; i < m; i++) { if (!hset.contains(arr1[i])) hset.add(arr1[i]); } // loop to check if all elements of arr2 also // lies in arr1 for ( int i = 0 ; i < n; i++) { if (!hset.contains(arr2[i])) return false ; } return true ; } public static void main(String[] args) { int arr1[] = { 11 , 1 , 13 , 21 , 3 , 7 }; int arr2[] = { 11 , 3 , 7 , 1 }; int m = arr1.length; int n = arr2.length; if (isSubset(arr1, arr2, m, n)) System.out.println( "arr2 is a subset of arr1" ); else System.out.println( "arr2 is not a subset of arr1" ); } } // This code is contributed by Kamal Rawal |
C#
// C# code to find whether an array is // subset of another array using System; using System.Collections.Generic; class GFG { /* Return true if arr2[] is a subset of arr1[] */ public static bool isSubset( int [] arr1, int [] arr2, int m, int n) { HashSet< int > hset = new HashSet< int >(); // hset stores all the values of arr1 for ( int i = 0; i < m; i++) { if (!hset.Contains(arr1[i])) { hset.Add(arr1[i]); } } // loop to check if all elements // of arr2 also lies in arr1 for ( int i = 0; i < n; i++) { if (!hset.Contains(arr2[i])) { return false ; } } return true ; } // Driver Code public static void Main( string [] args) { int [] arr1 = new int [] {11, 1, 13, 21, 3, 7}; int [] arr2 = new int [] {11, 3, 7, 1}; int m = arr1.Length; int n = arr2.Length; if (isSubset(arr1, arr2, m, n)) { Console.WriteLine( "arr2 is a subset of arr1" ); } else { Console.WriteLine( "arr2 is not a subset of arr1" ); } } } // This code is contributed by Shrikant13 |
Note that method 1, method 2 and method 4 don’t handle the cases when we have duplicates in arr2[]. For example, {1, 4, 4, 2} is not a subset of {1, 4, 2}, but these methods will print it as a subset.
Please write comments if you find the above codes/algorithms incorrect, or find other ways to solve the same problem.
Recommended Posts:
- Find the minimum value to be added so that array becomes balanced
- Check if array elements are consecutive | Added Method 3
- k largest(or smallest) elements in an array | added Min Heap method
- Find if there is any subset of size K with 0 sum in an array of -1 and +1
- Find the sum of maximum difference possible from all subset of a given array.
- Find the smallest positive integer value that cannot be represented as sum of any subset of a given array
- Array with GCD of any of its subset belongs to the given array
- Find original array from encrypted array (An array of sums of other elements)
- Find an element in array such that sum of left array is equal to sum of right array
- Largest divisible subset in array
- Minimum product subset of an array
- Maximum product subset of an array
- Find minimum value to assign all array elements so that array product becomes greater
- Given a sorted array and a number x, find the pair in array whose sum is closest to x
- Find the Initial Array from given array after range sum queries