Given a string, find the first element which is non -repetitive

that element must not be present anywhere else in the string.

Eg : Input : teeterson
Output : r, as it is the first element which
is non repetitive.

function findthefirstNonRepetitiveString(input) {
let inputArr = input.split(‘’)
let map = new Map()
let nonrepetaedString = “”

for (let i = 0; i < inputArr.length; i++) {
//if duplicate set true
if (map.has(inputArr[i])) {
map.set(inputArr[i], true)
} else {
map.set(inputArr[i], false)
}
}
map.forEach(function(v, k) {
if (!v) {
nonrepetaedString = k;
map.clear()
}
})

return nonrepetaedString
}

console.log(findthefirstNonRepetitiveString(“teeterson”))

--

--