105. find the first duplicate character in a string

JavaScriptApple
Is this helpful ?

from all members: - accepted / - tried

Given a string which might have duplicate letters, write a function to find the first duplicate.


firstDuplicate('abca')
// 'a'

firstDuplicate('abcdefe')
// 'e'

firstDuplicate('abcdef')
// null

What is the time & space cost of your approach ? Can you do better?

Let's try to solve this problem within 10 mintues.

Discuss(19)