if(n<m) return "No";
map<int,int> mp;
for(int i=0;i<n;i++)
{
mp[a1[i]]++;
}
for(int i=0;i<m;i++)
{
if(mp.find(a2[i]) != mp.end())
{
if(mp[a2[i]] == 0)
{
return "No";
}
mp[a2[i]]--;
continue;
}else{
return "No";
}
}
return "Yes";
}
string isSubset(int a1[], int a2[], int n, int m)
{
int i=0;
int count=0;
int j=0;
sort(a1,a1+n);
sort(a2,a2+m);
while(i<n and j<m)
{
if(a1[i]==a2[j])
{
i++;
j++;
count++;
}
else if(a1[i]<a2[j])
{
i++;
}
else
{
return "No";
}
}
if(count==m)
{
return "Yes";
}
return "No";
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter