Make two arrays equal by reversing subarrays
November 15, 2022
array-and-hashmapProblem URL: Make two arrays equal by reversing subarrays
We can sort both arrays and compare them. If they are equal, then we can make the two arrays equal by reversing subarrays.
class Solution:
def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
return sorted(target) == sorted(arr)
Time complexity: O(nlog(n))
Space complexity: O(1)