Find a recurring character in a string
This is a most commonly asked interview question there many ways to solve this for here we will look for an optimal solution with minimal time complexity
Question: find the recurring characters in a string
input string “ABCDABB”
Step 1 — first split the string for iterating
Step -2 stored strings which are not already stored
Step-3 compare with store to check if they are duplicate
function findRecurStr(input) {
let map = new Map()
let inputStrArr = input.slice()
for (let i = 0; i < inoutStrArr.length; i++) {
if (map.has(inputStrArr[i])) {
map.set(inputStrArr[i], map.get(inputStrArr[i]) + 1)
console.log(inputStrArr[i])
}
else {
map.set(inputStrArr[i], 1)
}
}
}
findRecurStr(“ABCDABB”)
The best book for cracking coding interview in my experience , available on amazon, link is below book
