https://leetcode.com/problems/first-letter-to-appear-twice/



Runtime: 42 ms, faster than 67.82% of Python3 online submissions for First Letter to Appear Twice.

Memory Usage: 13.9 MB, less than 7.59% of Python3 online submissions for First Letter to Appear Twice.



```python
class Solution:
    def repeatedCharacter(self, s: str) -> str:
        #5:53
        map_ = {}
        for index, char in enumerate(s):
            if char in map_.keys():
                if (len(map_[char]) >= 2):
                    continue
                map_[char].append(index)
            else:
                map_[char] = [index]
        duplicated_items = [item for item in map_.items() if len(item[1]) >= 2]
        duplicated_items = list(sorted(duplicated_items, key=lambda item: item[1][1]))
        #print(duplicated_items)
        return duplicated_items[0][0]
        #5:59
        #debug until 6:04
        #then read the needs, debug again to realize it ask us to return the first letter that appear twice
        #which means we only need to use the second element of the index array as the sort key
        #[('c', [2, 3]), ('b', [1, 4]), ('a', [0, 5])], we return 'c', even though they have equal sum

```

___


When do you use Go/Java for your backend service?

When you have millions of users.

But trust me, most of you guys won't make it.

So node/python/php would be fine for small businesses.
