For this Question: You are given a string S (containing only lowercase characters). You need to print the repeated character whose first appearance is leftmost.The first line of input contains T denoting the number of testcases. T testcases follow. 
Each testcase contains one line of input containing the string S.

Constraints:
1 <= T <= 100
1 <= |S| <= 1000For each testcase, in a new line, print the character. If not found then print "-1".Input:
2
geeksforgeeks
abcd

Output:
g
-1

Explanation:
Testcase1: We see that both e and g repeat as we move from left to right. But the leftmost is g so we print g.
Testcase2: No character repeats so we print -1.
 , I have written this Solution Code: 
    function leftMostOcurringChar(str) {
        // write code here
        // do not console.log answer
        // return the answer using return keyword
        let firstIndex = new Array(256).fill(-1);

   
        let res = Number.MAX_VALUE;
        for (let i = 0; i < str.length; i++)
        {
            if (firstIndex[str[i].charCodeAt()] == -1)
            {
                firstIndex[str[i].charCodeAt()] = i;
            }
            else
            {
                res = Math.min(res, firstIndex[str[i].charCodeAt()]);
            }
        }
        const ans = (res == Number.MAX_VALUE) ? -1 : res;
if (ans === -1) return -1;
        return str[ans]
    }, In this Programming Language: JavaScript, Now tell me if this Code is compilable or not?