Given a string s consisting of lowercase English letters, return the first letter to appear twice.

Note:


	A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence of b.
	s will contain at least one letter that appears twice.


&nbsp;
Example 1:

Input: s = "abccbaacz"
Output: "c"
Explanation:
The letter 'a' appears on the indexes 0, 5 and 6.
The letter 'b' appears on the indexes 1 and 4.
The letter 'c' appears on the indexes 2, 3 and 7.
The letter 'z' appears on the index 8.
The letter 'c' is the first letter to appear twice, because out of all the letters the index of its second occurrence is the smallest.


Example 2:

Input: s = "abcdd"
Output: "d"
Explanation:
The only letter that appears twice is 'd' so we return 'd'.


&nbsp;
Constraints:


	2 &lt;= s.length &lt;= 100
	s consists of lowercase English letters.
	s has at least one repeated letter.


class Solution:
    def repeatedCharacter(self, s: str) -> str:
        occurences = defaultdict(int)
        for char in s:
            occurences[char] += 1
            if occurences[char] == 2:
                return char
class Solution {
    public char repeatedCharacter(String s) {
        HashSet<Character> hset = new HashSet<>();
        for(char ch:s.toCharArray())
        {
            if(hset.contains(ch))
                return ch;
            else
                hset.add(ch);
        }
        return ' ';
    }
}
class Solution
{
public:
    char repeatedCharacter(string s)
    {
        unordered_map<char, int> mp; //for storing occurrences of char

        char ans;
        for(auto it:s)
        {
            if(mp.find(it) != mp.end()) //any char which comes twice first will be the ans;
            {
                ans = it;
                break;
            }
            mp[it]++; //increase the count of char
        }
        return ans;
    }
};
 var repeatedCharacter = function(s) {
    const m = {};
    
    for(let i of s) {
        if(i in m) {
            m[i]++
        } else {
            m[i] = 1
        }
        
        if(m[i] == 2) {
            return i
        }
    }
};
First Letter to Appear Twice