# First Non Repeating Character

![](https://3743232000-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHW2IQuh2PFpWJDvBz2FF%2Fuploads%2Fgit-blob-eadddc6382034a2b67a0e2b472e4dede83b5cc9b%2FScreenshot%202023-01-20%20at%2021.16.11.png?alt=media)

* n, 1 (alphabet 26 constant)

```jsx
function firstNonRepeatingCharacter(str) {
  const memo = {}
  for (let i = 0; i < str.length; i++) {
    const c = str[i];
    if (memo[c] === undefined) memo[c] = 0;
    memo[c] += 1;
  }

  for (let i = 0; i < str.length; i++) {
    const c = str[i];
    if (memo[c] === 1) return i;
  }
  
  return -1;
}

// Do not edit the line below.
exports.firstNonRepeatingCharacter = firstNonRepeatingCharacter;
```
