Make Two Arrays Equal by Reversing Sub-arrays LeetCode solution in Java
1class Solution {2public boolean canBeEqual(int[] target, int[] arr) {3HashMap<Integer, Integer> hm1 = new HashMap();4for (int i : arr) {5if (hm1.containsKey(i)) hm1.put(i, hm1.get(i) + 1);6else hm1.put(i, 1);7}8for (int i : target) {9if (hm1.containsKey(i)) {10hm1.put(i, hm1.getOrDefault(i, 0) - 1);11if (hm1.get(i) == 0) hm1.remove(i);12} else return false;13}14if (hm1.size() == 0) return true;1516return false;17}18}