Skip to main content

1460. Make Two Arrays Equal by Reversing Subarrays

  • Sort
class Solution {
public:
bool canBeEqual(vector<int>& target, vector<int>& arr)
{
sort(target.begin(), target.end());
sort(arr.begin(), arr.end());

for (int i = 0; i < target.size(); ++i)
{
if (target[i] != arr[i]) return false;
}
return true;
}
};
  • T: O(nlogn)O(n \cdot \log n)
  • S: O(logn)O(\log n)