Longest Substring without Repeating Characters - Java code with Explanation

preview_player
Показать описание
Given a string, find the length of the longest substring without repeating characters. In this tutorial, You are going to learn how to find the longest substring without repeating character using sliding window approach.

Рекомендации по теме
Комментарии
Автор

If j visits an element already present in the set then why we are removing the element present at the i'th index of string? It is not always that i and j are pointing to same character (when j points to a repeating character).

bhaskarmahajan
Автор

can you please do the video for Minimum Window Substring.
I have seen many videos for this problem. kind of confused. I like your teaching .
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).

Example:

Input: S = "ADOBECODEBANC", T = "ABC"
Output: "BANC"

dimmyt
Автор

Great explanation, however I have one question. While following along with you during the iterations, our last iteration is ["a", "c", "b"] while the answer states the output should be ["a", "b", "c"] can you please clarify why it is different?

AlinaKay
Автор

sir why u have taken HashSet inplace of that u can easily use ArrayList, then why u implemented hashset

snehkumar
Автор

ouput length is correct.while printing set it gives less elements...any help?

saebalam
Автор

This code does not work for "werfvbjisrgvbn" . Its Correct output is:
9 . And Your Code's output is: 11

ishikathakur
Автор

Sir I want same code for c++.
Facing prblm in hashmap() line

Bobby-mffw
Автор

Sir I want the program for find the max sub string of one String ? i.e input is 'banana' and the output is 'nana'.

saikrishnamraju
Автор

What is the space complexity here? Is it O(n)?

vinamra
Автор

after removal of first a there is no code of additon of a in set in else part of a loop

vishalmishra
Автор

This algorithm fails for "abcbcdefg". Expected ans is 6, but it gives 7.

suyogkharage
Автор

if the hashset contains the character then if condition fails then how the value of j increases

ashish
Автор

If abcdefeghiklm dn this will not work..

SrijoniChakraborty
Автор

your logic is not working for this test case "pwwkew"

pythonists