Pergunta de entrevista da empresa Workday
During the phone interview, the coding question was done on a google doc and asked: In Java, given a String of [a-z] characters, find and return the first character that appears only once. I implemented it using a counting array and in the end the manager asked if I could implement it in another way, which I mentioned I could do it using a HashMap.
Respostas da entrevista
Prasad, your time complexity is O(n^2). It can be solved in O(n).
Also, you're using O(n) space while you can solve it with only O(1) space.
For(i in a to z)
Count[i]=0
Index[i] = -1
For(j in 0 to len(string))
c = string.charAt(j)
Count[c] += 1
If( index[c]==-1) index[c] = j
Find count=1 and smallest index that is not -1
String input = "abcabcdedfek";
char result = 0;
char[] ignoreArray = new char[input.length()];
int k=0;
for (int i=0;i