Pergunta de entrevista da empresa Google

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

Resposta da entrevista

Sigiloso

2 de set. de 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 ' '; }