We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java solution using a Integer, Boolean map. Idea is to negate whatever bool is found in the map for each value. If it isn't already in the map put false. Increment a counter when something is made true.
// Write your code here
HashMap map = new HashMap<>();
int pairs = 0;
System.out.println(map);
for(Integer i : ar){
map.put(i, !map.getOrDefault(i,true));
if(map.get(i) == true){pairs++;}
}
S
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →
Java solution using a Integer, Boolean map. Idea is to negate whatever bool is found in the map for each value. If it isn't already in the map put false. Increment a counter when something is made true. // Write your code here HashMap map = new HashMap<>(); int pairs = 0; System.out.println(map); for(Integer i : ar){ map.put(i, !map.getOrDefault(i,true)); if(map.get(i) == true){pairs++;} } S }
}