Java code.
Time & space: both O(n).
public int firstUniqChar(String s) {
int[] freq = new int[26];
Map map = new LinkedHashMap<>();
for (int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
switch(freq[c - 'a']++) {
case 0: map.put(c, i); break;
case 1: map.remove(c); break;
}
}
return map.isEmpty() ? -1 : map.values().iterator().next();
}