Given two integer arrays of equal length target and arr.
In one step, you can select any non-empty sub-array of arr and reverse it. You are allowed to make any number of steps.
Return True if you can make arr equal to target, or False otherwise.
 
Example 1:
Input: target = [1,2,3,4], arr = [2,4,1,3]
Output: true
Explanation: You can follow the next steps to convert arr to target:
1- Reverse sub-array [2,4,1], arr becomes [1,4,2,3]
2- Reverse sub-array [4,2], arr becomes [1,2,4,3]
3- Reverse sub-array [4,3], arr becomes [1,2,3,4]
There are multiple ways to convert arr to target, this is not the only way to do so.

Example 2:
Input: target = [7], arr = [7]
Output: true
Explanation: arr is equal to target without any reverses.

Example 3:
Input: target = [1,12], arr = [12,1]
Output: true

Example 4:
Input: target = [3,7,9], arr = [3,7,11]
Output: false
Explanation: arr doesn't have value 9 and it can never be converted to target.

Example 5:
Input: target = [1,1,1,1,1], arr = [1,1,1,1,1]
Output: true

 
Constraints:

target.length == arr.length
1 <= target.length <= 1000
1 <= target[i] <= 1000
1 <= arr[i] <= 1000

Difficulty: EASY
Starter code: class Solution:
    def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
        

Solutions:
class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		return sorted(target) == sorted(arr)


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		if sorted(target) == sorted(arr):
			return True
		else:
			return False


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		if sum(arr) != sum(target):
			return False
		boolean = True
		for (i, v) in enumerate(target):
			if v in arr:
				boolean = True & boolean
			else:
				boolean = False & boolean
		return boolean


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		result = all((elem in target for elem in arr))
		if result:
			return sorted(arr) == sorted(target)
		else:
			return False


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		for i in range(len(target)):
			if target[i] not in arr:
				return False
			arr.pop(arr.index(target[i]))
		return True


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		for i in arr:
			if i in target:
				target.remove(i)
			else:
				return False
		return True


from collections import Counter

class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		arr_counter = Counter(target)
		tgt_counter = Counter(arr)
		return arr_counter == tgt_counter


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		if collections.Counter(target) != collections.Counter(arr):
			return False
		return True

		def reverse(left, right):
			while left < right:
				(arr[left], arr[right]) = (arr[right], arr[left])
				left += 1
				right -= 1
		for i in range(len(target)):
			if target[i] == arr[i]:
				continue
			j = arr.find(target[i])
			reverse(i, j)


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		return Counter(target) == Counter(arr)


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		import numpy as np
		return (np.sort(target) == np.sort(arr)).all()


def sort(list_a):
	low = []
	high = []
	if len(list_a) <= 1:
		return list_a
	else:
		v = list_a.pop()
		for i in range(len(list_a)):
			if list_a[i] > v:
				high.append(list_a[i])
			else:
				low.append(list_a[i])
		return sort(low) + [v] + sort(high)

class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		target = sort(target)
		arr = sort(arr)
		if arr == target:
			return True
		else:
			return False


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		if len(target) != len(arr):
			return False
		mp = {}
		for num in target:
			mp[num] = mp.get(num, 0) + 1
		for num in arr:
			if num not in mp:
				return False
			mp[num] -= 1
			if mp[num] < 0:
				return False
		return True


class Solution:

	def canBeEqual(self, target, arr) -> bool:
		target = sorted(target)
		arr = sorted(arr)
		return target == arr


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		if len(target) != len(arr):
			return False
		p = 0
		a = sorted(arr)
		t = sorted(target)
		while p < len(t):
			if a[p] != t[p]:
				return False
			p += 1
		return True


class Solution:

	def partition(self, arr, start, end):
		follower = leader = start
		while leader < end:
			if arr[leader] <= arr[end]:
				(arr[leader], arr[follower]) = (arr[follower], arr[leader])
				follower += 1
			leader += 1
		(arr[follower], arr[end]) = (arr[end], arr[follower])
		return follower

	def quicksort(self, arr, start, end):
		if start >= end:
			return
		else:
			p = self.partition(arr, start, end)
			self.quicksort(arr, p + 1, end)
			self.quicksort(arr, start, p - 1)

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		self.quicksort(arr, 0, len(arr) - 1)
		self.quicksort(target, 0, len(arr) - 1)
		return target == arr


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		for i in target:
			if i not in arr:
				return False
			arr[arr.index(i)] = None
		return True


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		for i in range(len(target)):
			for j in range(i, len(target)):
				if arr[j] == target[i]:
					break
			else:
				return False
			arr[i:j + 1] = reversed(arr[i:j + 1])
		return arr == target


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		count = 0
		for item in target:
			if item not in arr:
				return False
		hash_map_arr = {}
		hash_map_target = {}
		for i in range(len(arr)):
			if arr[i] not in hash_map_arr:
				hash_map_arr[arr[i]] = 1
			else:
				hash_map_arr[arr[i]] += 1
			if target[i] not in hash_map_target:
				hash_map_target[target[i]] = 1
			else:
				hash_map_target[target[i]] += 1
		for item in target:
			if hash_map_arr[item] != hash_map_target[item]:
				return False
		return True


class Solution:

	def compare(self, x, y):
		x_ = set(x)
		for i in x_:
			if x.count(i) != y.count(i):
				return False
		return True

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		return self.compare(target, arr)


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		for i in arr:
			if i not in target:
				return 0
			else:
				target.remove(i)
		else:
			return 1


from collections import Counter

class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		c1 = Counter(target)
		c2 = Counter(arr)
		return not set(c1.keys()).symmetric_difference(set(c2.keys())) and all([c1[k1] == c2[k1] for k1 in c1])


from collections import defaultdict

class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		if len(target) != len(arr):
			return False
		numbers = defaultdict(int)
		for val in arr:
			numbers[val] += 1
		for val in target:
			numbers[val] -= 1
		print(numbers)
		if min(numbers.values()) == 0 and max(numbers.values()) == 0:
			return True
		return False


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		d1 = {}
		d2 = {}
		for i in target:
			if i not in d1:
				d1[i] = 1
			else:
				d1[i] += 1
		for i in arr:
			if i not in d2:
				d2[i] = 1
			else:
				d2[i] += 1
		for (k, v) in d1.items():
			if k not in d2:
				return False
			elif v != d2[k]:
				return False
		return True


class Solution:

	def canBeEqual(self, target: List[int], arr: List[int]) -> bool:
		differences_dict = {}
		for i in range(len(target)):
			differences_dict[target[i]] = differences_dict.get(target[i], 0) + 1
			differences_dict[arr[i]] = differences_dict.get(arr[i], 0) - 1
			if not differences_dict[target[i]]:
				differences_dict.pop(target[i])
			if arr[i] != target[i] and (not differences_dict[arr[i]]):
				differences_dict.pop(arr[i])
		return False if differences_dict else True