1460. Make Two Arrays Equal by Reversing Sub-arrays

1460. Make Two Arrays Equal by Reversing Sub-arrays

class Solution {
    public boolean canBeEqual(int[] target, int[] arr) {
        HashMap<Integer,Integer> h = new HashMap<>();
        for (int a: arr){
            h.put(a ,h.getOrDefault(a,0)+1);
        for(int b: target){
            if(h.get(b)!= null)
            else return false;
        for(int c: h.keySet()){
            if(h.get(c) != 0) return false;
        return true;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s