2
public int longestAwesome(String s) {3
Map<Integer, Integer> map = new HashMap<>();8
for (int i = 0; i < s.length(); i++) {9
int bit = (1 << (s.charAt(i) - '0'));10
state ^= bit; // if odd freq then it becomes even or if even becomes odd12
if (map.containsKey(state)) ans = Math.max(ans, i - map.get(state));14
for (int odd = 0; odd <= 9; odd++) { // become odds one by one15
int mask = (1 << odd);17
Integer j = map.get(state ^ mask);19
if (j != null) ans = Math.max(ans, i - j);22
if (!map.containsKey(state)) map.put(state, i);