Java Solution  -  Problem for input 9498331 => 93139 ans should be 5 but leet code show 3
class Solution {\n    public int longestAwesome(String string) {\n\t\tList list1 = new ArrayList<>();\n\t\tList list2 = new ArrayList<>();\n\t\tMap map = new Ha
class Solution {\n    public int longestAwesome(String string) {\n\t\tList<Integer> list1 = new ArrayList<>();\n\t\tList<Integer> list2 = new ArrayList<>();\n\t\tMap<Character, Integer> map = new HashMap<Character, Integer>();\n\t\tfor(int i=0; i<string.length();i++) {\n\t\t\tif(map.containsKey(string.charAt(i))) {\n\t\t\t\tmap.put(string.charAt(i), map.get(string.charAt(i))+1);\n\t\t\t}\n\t\t\tmap.putIfAbsent(string.charAt(i), 1);\n\t\t}\n\n\t\tfor(Character c1 : map.keySet()) {\n\t\t\tint value = map.get(c1);\n\t\t\tif(value > 1) {\n\t\t\t\tif(value % 2 == 0 ) {\n\t\t\t\t\tlist1.add(value);\n\t\t\t\t}else {\n\t\t\t\t\tlist1.add(value-1);\n\t\t\t\t}\n\n\t\t\t}else {\n\t\t\t\tlist2.add(map.get(c1));\n\t\t\t}\n\t\t}\n\n\t\tif(list1.size() == 0)\n\t\t\treturn 0;\n\n\t\tif(list2.size() == 0) \n\t\t\treturn list1.stream().mapToInt(Integer::intValue).sum();\n\n\t\treturn list1.stream().mapToInt(Integer::intValue).sum()+1;\n    }\t\n}
[]