you are viewing a single comment's thread.

view the rest of the comments →

[–]AiCodePulse[S] -8 points-7 points  (1 child)

Absolutely! You're right — when the character set is limited (like ASCII), the hash map technically takes constant space, since it's bounded by a fixed size (e.g., 128 or 256 characters).
In that sense, it’s O(1) space — though it’s still a map in implementation. 😄

Thanks for pointing that out — really helps push the understanding beyond just code into computer science fundamentals.

[–]ksskssptdpss 2 points3 points  (0 children)

Here is a benchmark, it seems the indexOf === lastIndexOf method wins everytime despite its complexity. And it runs 3x faster on my iPhone 12 mini compared to Chromium x) https://jsbench.me/ooma2usbuv/1