---
title: "Discussion on \"Javascript: Use a Hash Map to solve \"First Non-Repeating Character\" in O(n) time\" | Hashnode"
description: "Discussion on \"Javascript: Use a Hash Map to solve \"First Non-Repeating Character\" in O(n) time\". Solve \"First Non Repeating Character\" in JavaScript with hash maps; optimize LeetCode algorithms for O(n) complexity"
url: "https://hashnode.com/posts/javascript-use-a-hash-map-to-solve-first-non-repeating-character-in-on-time/6478e74ea9c3b8fbbc775bbe"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Javascript: Use a Hash Map to solve "First Non-Repeating Character" in O(n) time](https://blog.austn.net/javascript-use-a-hash-map-to-solve-first-non-repeating-character-in-on-time?utm_source=hashnode&utm_medium=feed)

Solve "First Non Repeating Character" in JavaScript with hash maps; optimize LeetCode algorithms for O(n) complexity

Jun 1, 2023 · 4 min read · blog.austn.net  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#algorithms](https://hashnode.com/tag/algorithms)
-   [#leetcode-solution](https://hashnode.com/tag/leetcode-solution)
-   [#technical-interview](https://hashnode.com/tag/technical-interview)
-   [#data-structures](https://hashnode.com/tag/data-structures)

## Written by

[Austin](https://hashnode.com/@austn)

@austn

  
[View profile](https://hashnode.com/@austn)

Software Engineer

Professional software engineer working at CoverMyMeds, an enterprise healthtech firm that ensures patients get access to the medication they need. Primarily focused on backend and systems design through Ruby and Elixir, but experienced with JavaScript and all things frontend Interested in learning and teaching the craft of software; technical or otherwise Join me as I innovate by iterating!

## Responses 1

Markdown supported · ⌘↵ to post

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jun 2, 2023](https://hashnode.com/posts/javascript-use-a-hash-map-to-solve-first-non-repeating-character-in-on-time/6478e74ea9c3b8fbbc775bbe/comment/647a27331c128bf71962a1b2)

Hey, you're back! Well, for this I'd use a simple two column array

BASIC code at [forums.craigslist.org](https://forums.craigslist.org/?ID=326981539)

I neglected to put a guard around that first For loop in case the string was empty, oops

[Austin](https://hashnode.com/@austn)

[Jun 2, 2023](https://hashnode.com/posts/javascript-use-a-hash-map-to-solve-first-non-repeating-character-in-on-time/6478e74ea9c3b8fbbc775bbe/comment/647a27331c128bf71962a1b2#reply-647a2c49cc9d6bf749df536e)

Glad to be back :)

I never would have thought of using ASCII math, that's a neat tactic. This would be another O(n) solution right?

I wonder how long it'll be until I post one of these that you couldn't solve in BASIC, you're quick!

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jun 2, 2023](https://hashnode.com/posts/javascript-use-a-hash-map-to-solve-first-non-repeating-character-in-on-time/6478e74ea9c3b8fbbc775bbe/comment/647a27331c128bf71962a1b2#reply-647a43631c128bf71962a55e)

[Austin](https://hashnode.com/@austn) It's O(n) since it's one pass through the string and then one pass through the array whose size is constant no matter how big the string gets.

Bring it on! If I can't quickly solve it in BASIC, I probably could in 1983 8-bit Atari LOGO

Still more edits lol — If you're looking for some really crazy challenges, try some Knuth

[yetanothertroll](https://hashnode.com/@yetanothertroll)

[Jan 19, 2025](https://hashnode.com/posts/javascript-use-a-hash-map-to-solve-first-non-repeating-character-in-on-time/6478e74ea9c3b8fbbc775bbe/comment/647a27331c128bf71962a1b2#reply-678d8a243076f504bc0f0319)

[Austin](https://hashnode.com/@austn) Hey, you still alive? Is this an actual leetcode problem? If so, I can't find it. I'm mainly tackling the hard problems in C (the closest thing to BASIC they have lol) but I figured I'd convert the BASIC solutions I posted back in 2023 to C and actually submit them

EDIT: Is it 387. First Unique Character in a String? Looks like it
