Subset Check Problem Statement
Determine if one array is a subset of another given two integer arrays ARR1
and ARR2
of lengths 'N' and 'M' respectively.
Return True if ARR2
is a subset of ARR1
, otherwise return False.
Input:
The first line contains a single integer T, indicating the number of test cases.
Each test case contains:
- An integer N, the length of the first array ARR1.
- A line with N space-separated integers indicating the elements of ARR1.
- An integer M, the length of the second array ARR2.
- A line with M space-separated integers indicating the elements of ARR2.
Output:
For each test case, output "true" if ARR2 is a subset of ARR1, otherwise output "false".
Output should be given on a new line for each test case.
Example:
Example 1:
Input: ARR1 = [1, 2, 3], ARR2 = [1, 2]
Output: true
Example 2:
Input: ARR1 = [1, 2, 3], ARR2 = [1, 2, 2]
Output: false
Constraints:
- 1 <= T <= 10
- 1 <= N <= 105
- 0 <= ARR1[i] <= 109
- 1 <= M <= 105
- 0 <= ARR2[i] <= 109
- Time Limit: 1 sec
Note:
Focus on implementing the function logic as printing has already been managed.
AnswerBot
1d
Check if one array is a subset of another array.
Iterate through elements of ARR2 and check if each element is present in ARR1.
Use a set data structure to efficiently check for element presence.
Return ...read more
Help your peers!
Add answer anonymously...
Top Amazon Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Top HR questions asked in Amazon Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app