array and hashmap November 15, 2022

Make two arrays equal by reversing subarrays

Time O(nlog(n)) Space O(1) Open original problem

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)