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
4mo
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...
Amazon Software Developer Intern interview questions & answers
A Software Developer Intern was asked 4mo agoQ. Given a linked list, find the n'th node from the end of the list.
A Software Developer Intern was asked 4mo agoQ. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ. Given a matrix, find the shortest distance between two given points located anyw...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked 4mo agoQ1. Given a linked list, find the n'th node from the end of the list.
A Software Developer Intern was asked 4mo agoQ2. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ3. Given a matrix, find the shortest distance between two given points located anyw...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

