Medium Problems

3. Longest Substring Without Repeating Characters

Solutions

function lengthOfLongestSubstring(s: string): number {
  function check(start: number, end:number) {
      let set = new Set();
      for (let i = start; i < end + 1; i++) {
          let c = s[i];
          if(set.has(c)) {
              return false;
          }
          set.add(c)
      }
      return true;
  }
  
  let res = 0;
  for (let i = 0; i < s.length; i++) {
      for(let j = i; j < s.length; j++) {
          if(check(i,j)) {
              res = Math.max(res, j - i + 1)
          }
      }
  }
  return res;
};

Video Solution

Last Update: 12:08 - 16 April 2024
Hash Table
String
Sliding Window

On this page