MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

MakeTwoArraysEqualbyReversingSubarrays.java:5–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4//Double map solution
5class Solution {
6 public boolean canBeEqual(int[] target, int[] arr) {
7 HashMap<Integer,Integer> map1 = new HashMap<>();
8 for(int element : target){
9 map1.put(element, map1.getOrDefault(element,0)+1);
10 }
11
12 HashMap<Integer,Integer> map2 = new HashMap<>();
13 for(int element : arr){
14 map2.put(element, map2.getOrDefault(element,0)+1);
15 }
16
17 for(int key : map1.keySet()){
18 if(!map2.containsKey(key)){
19 return false;
20 }
21 if(map1.get(key)!=map2.get(key)){
22 return false;
23 }
24 }
25 return true;
26 }
27}
28
29//single map solution
30class Solution {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected