#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
bool cmp_with_sort(std::vector<int> arr1, std::vector<int> arr2)
{
if(arr1.size()!=arr2.size())
return false;
std::sort(arr1.begin(), arr1.end());
std::sort(arr2.begin(), arr2.end());
bool arrs_equal = true;
for(int i=0;arrs_equal && i<arr1.size();++i)
if(arr1[i]!=arr2[i])
arrs_equal=false;
return arrs_equal;
}
bool cmp_with_sets(const std::vector<int>& arr1, const std::vector<int>& arr2)
{
if(arr1.size()!=arr2.size())
return false;
std::multiset<int> set1(arr1.begin(),arr1.end());
std::multiset<int> set2(arr2.begin(), arr2.end());
return set1==set2;
}
bool cmp_nested_loops(const std::vector<int>& arr1, const std::vector<int>& arr2)
{
if(arr1.size()!=arr2.size())
return false;
for(int i=0;i<arr1.size();i++)
{
bool found = false;
for(int j=0;!found && j<arr2.size();j++)
if(arr1[i]==arr2[j])
found = true;
if(!found)
return false;
}
return true;
}
int main() {
std::vector<int> arr1 {4,1,2,1};
std::vector<int> arr2 {1,4,1,2};
std::cout << (cmp_with_sort(arr1,arr2)?"Equal":"Not equal") << "\n";
std::cout << (cmp_with_sets(arr1,arr2)?"Equal":"Not equal") << "\n";
std::cout << (cmp_nested_loops(arr1,arr2)?"Equal":"Not equal") << "\n";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKYm9vbCBjbXBfd2l0aF9zb3J0KHN0ZDo6dmVjdG9yPGludD4gYXJyMSwgc3RkOjp2ZWN0b3I8aW50PiBhcnIyKQp7CglpZihhcnIxLnNpemUoKSE9YXJyMi5zaXplKCkpCgkJcmV0dXJuIGZhbHNlOwoJc3RkOjpzb3J0KGFycjEuYmVnaW4oKSwgYXJyMS5lbmQoKSk7CglzdGQ6OnNvcnQoYXJyMi5iZWdpbigpLCBhcnIyLmVuZCgpKTsKCWJvb2wgYXJyc19lcXVhbCA9IHRyd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