2023-10-23 23:16:24 +02:00
|
|
|
import readline from "node:readline"
|
2021-06-09 20:31:45 +02:00
|
|
|
|
|
|
|
const input = []
|
|
|
|
const readlineInterface = readline.createInterface({
|
|
|
|
input: process.stdin,
|
2023-10-23 23:16:24 +02:00
|
|
|
output: process.stdout,
|
2021-06-09 20:31:45 +02:00
|
|
|
})
|
2023-10-23 23:16:24 +02:00
|
|
|
readlineInterface.on("line", (value) => {
|
2021-06-09 20:31:45 +02:00
|
|
|
input.push(value)
|
|
|
|
})
|
2023-10-23 23:16:24 +02:00
|
|
|
readlineInterface.on("close", solution)
|
2021-06-09 20:31:45 +02:00
|
|
|
|
|
|
|
const firstNonRepeatingCharacter = (string) => {
|
2020-11-15 11:40:06 +01:00
|
|
|
const lettersCount = {}
|
|
|
|
for (let index = 0; index < string.length; index++) {
|
|
|
|
const character = string[index]
|
|
|
|
if (lettersCount[character] == null) {
|
|
|
|
lettersCount[character] = {
|
|
|
|
total: 1,
|
|
|
|
firstIndex: index,
|
2023-10-23 23:16:24 +02:00
|
|
|
value: character,
|
2020-11-15 11:40:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lettersCount[character].total += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let result = null
|
|
|
|
for (const character in lettersCount) {
|
|
|
|
const characterObject = lettersCount[character]
|
|
|
|
if (characterObject.total === 1) {
|
|
|
|
if (result == null) {
|
|
|
|
result = characterObject
|
|
|
|
} else if (characterObject.firstIndex < result.firstIndex) {
|
|
|
|
result = characterObject
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == null) {
|
2023-10-23 23:16:24 +02:00
|
|
|
return ""
|
2020-11-15 11:40:06 +01:00
|
|
|
}
|
|
|
|
return result.value
|
|
|
|
}
|
|
|
|
|
2021-06-09 20:31:45 +02:00
|
|
|
function solution() {
|
|
|
|
console.log(firstNonRepeatingCharacter(input[0]))
|
|
|
|
}
|