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.
public static int sockMerchant(int n, List<Integer> ar) {
// Write your code here
int sockesPair = 0;
HashMap<Integer, Integer> map = new HashMap<>();
for (int i : ar) {
if (map.containsKey(i)) {
map.put(i, map.get(i) + 1);
} else {
map.put(i, 1);
}
}
for (int i : map.keySet()) {
sockesPair += (map.get(i) / 2);
}
return sockesPair;
}
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(8)