Array Subset of another array

Question Given two arrays: a1[0..n-1] of size n and a2[0..m-1] of size m. Task is to check whether a2[] is a subset of a1[] or not. Both the arrays can be sorted or unsorted. Example 1: Input: a1[] = {11, 1, 13, 21, 3, 7} a2[] = {11, 3, 7, 1} Output: Yes Explanation: a2[] is a subset of a1[] Example 2: Input: a1[] = {1, 2, 3, 4, 5, 6} a2[] = {1, 2, 4} Output: Yes Explanation: a2[] is a subset of a1[] Solution string isSubset(int a1[], int a2[], int n, int m) { mapa; mapb; int d=INT_MIN; for(int i=0;ia[i]) return "No"; } return "Yes"; }

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones