Google Interview Question

given two strings where one string has exactly one more character than the other string. Code to find that additional character.

Interview Answer

Anonymous

Sep 2, 2018

static char additional(String a , String b) { int [] arr = new int [26]; for(char c: a.toCharArray()) { arr[c-'a']++; } for(char c:b.toCharArray()) { arr[c-'a']--; } for(int i=0;i<26;i++) { if(arr[i]==1)return (char)('a'+i); if(arr[i]==-1)return (char)('a'+i); } return ' '; }