Skip to content

Instantly share code, notes, and snippets.

View nidzovito's full-sized avatar

nidzovito nidzovito

View GitHub Profile
@nidzovito
nidzovito / lengthOfLongestSubstring.js
Last active December 2, 2022 02:48
Algorithm to find the longest substring without repeating characters
// Given a string "input", find the length of the longest substring without repeating characters.
const lengthOfLongestSubstring = (input = "") => {
const chars = input.split("");
let buffer = new Map(); // stores the last index for each encountered character
let maxLen = 0;
for (let index = 0; index < chars.length; index++) {
const char = chars[index];
if (!buffer.has(char)) {