Find a recurring character in a string

Abhijit chakra
Oct 12, 2020

--

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

https://amzn.to/3cFjyGy

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response