Tried different approaches for this problem, nothing working for one requirement while verification, take some time off your 100k job and please help.
package com.codegym.task.task08.task0815;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
/*
Census
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("1", "Jab");
map.put("2", "Bhi");
map.put("3", "Koi");
map.put("4", "Ladki");
map.put("5", "Jab");
map.put("6", "Dekhu");
map.put("7", "Mera");
map.put("8", "Dil");
map.put("9", "Deewana");
map.put("10", "Bole");
return map;
}
public static int getCountTheSameFirstName(HashMap<String, String> map, String name) {
int count=0, lcount=0;
// for (String value : map.values()) {
for (Map.Entry<String, String> m : map.entrySet()) {
String value = m.getValue();
count = 0;
if (value.equals(name)) {
count++;
}
if (count>lcount)
lcount=count;
}
return lcount;
}
public static int getCountTheSameLastName(HashMap<String, String> map, String lastName) {
int count=0, lcount=0;
for (String key : map.keySet()) {
count=0;
if (key.equals(lastName)) {
count++;
}
if (count>lcount)
lcount=count;
}
return lcount;
}
public static void main(String[] args) {
// HashMap<String, String> map = new HashMap<String, String>();
// map = createMap();
// System.out.println(getCountTheSameFirstName(map, "Ajay"));
// System.out.println(getCountTheSameLastName(map, "Atul"));
}
}