Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 533 |

@akashverma4 | 291 |

@swastik8750 | 237 |

@nishunishuraj18 | 223 |

@nayan2709 | 211 |

@ajaybhardwaj1999 | 196 |

@surajmamgai | 193 |

@AnshikaPandey | 192 |

@gurshehzadsingh | 188 |

@shardul08 | 185 |

@Rajpra786 | 181 |

Complete Leaderboard |

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. It may be assumed that elements in both array are distinct.

**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[]

**Example 3:**

**Input**:
a1[] = {10, 5, 2, 23, 19}
a2[] = {19, 5, 3}**
Output**:
No**
Explanation:**
a2[] is not a subset of a1[]

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **isSubset()** which takes the array **a1[]**, **a2[]**, its size **n **and **m **as inputs and return "Yes" if arr2 is subset of arr1 else return "No" if arr2 is not subset of arr1.

**Expected Time Complexity:** O(n)

**Expected Auxiliary Space:** O(n)

**Constraints:**

1 <= n,m <= 10^{5}

1 <= a1[i], a2[j] <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Array Subset of another array

...