function solution(s) {
const lastSeen = {};
const result = [];
for (let i = 0; i < s.length; i++) {
const char = s[i];
if (char in lastSeen) {
const lastPosition = lastSeen[char];
result.push(i - lastPosition);
} else {
result.push(-1);
}
lastSeen[char] = i;
}
return result;
}