/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public int firstUniqueChar
(String str
) {
int index = -1;
str = str.toLowerCase();
Map
<Character, Integer
> charFreqMap
= new HashMap
<>();
// Update the map
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
// Get the current frequency
int freq = charFreqMap.getOrDefault(c, 0);
// Update the map
charFreqMap.put(c, (freq + 1));
}
for (int i = 0; i < str.length(); i++) {
if (charFreqMap.get(str.charAt(i)) == 1) {
index = i;
break;
}
}
return index;
}
{
// your code goes here
Ideone x = new Ideone();
System.
out.
println(x.
firstUniqueChar("lotsOfLove")); }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBpbnQgZmlyc3RVbmlxdWVDaGFyKFN0cmluZyBzdHIpIHsKCiAgICBpbnQgaW5kZXggPSAtMTsKICAgIHN0ciA9IHN0ci50b0xvd2VyQ2FzZSgpOwoKICAgIE1hcDxDaGFyYWN0ZXIsIEludGVnZXI+IGNoYXJGcmVxTWFwID0gbmV3IEhhc2hNYXA8PigpOwoKICAgIC8vIFVwZGF0ZSB0aGUgbWFwCiAgICBmb3IgKGludCBpID0gMDsgaSA8IHN0ci5sZW5ndGgoKTsgaSsrKSB7CiAgICAgIGNoYXIgYyA9IHN0ci5jaGFyQXQoaSk7CgogICAgICAvLyBHZXQgdGhlIGN1cnJlbnQgZnJlcXVlbmN5CiAgICAgIGludCBmcmVxID0gY2hhckZyZXFNYXAuZ2V0T3JEZWZhdWx0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