Length of longest substring without repeating characters | LeetCode problem number 3

preview_player
Показать описание
Length of longest substring without repeating characters

This is the #LeetCode question number 3 under medium section.

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

A hashset makes more sense here. Using arraylist will cause the solution to have quadratic complexity, but a hashset has O(1) lookup therefore using a hashset the algorithm would have O(n) time and space complexity

Garensonic
Автор

Well explained mam, for beginner's easily can understand

avinashabhi
Автор

🛠 Optimizations:
✅ HashSet instead of List → O(1) lookup instead of O(n)
✅ end - start instead of list.size() → Cleaner logic
✅ Space Complexity: O(n) (worst case, all unique characters)

public static int string) {
int start=0, end=0, max_length=0;
Set<Character> set= new HashSet<>();
while(end<string.length()){

set.add(string.charAt(end));
end++;
max_length=Math.max(max_length, end-start);
}else{

start++;
}

}
return max_length;
}

KapilDevmurari
Автор

Good explaination!💫

Edit: there is one more test case that is to check if string is null, we will have to return zero just noticed it after submitting it.

nikhilkumarjamwal
Автор

Please tell how to print, the longest substring along with count

karthikshan
Автор

class Solution {
public int label) {
int end = 0;
int maxLength = 0;
List<Character> list = new ArrayList<>();

while (end < label.length()) {
boolean isContained =
if (!isContained) {
list.add(label.charAt(end));
end++;
maxLength = Math.max(maxLength, list.size());
} else {
list.removeFirst();
}
}
return maxLength;
}
}

i think the start variable unnecessary

duylong
Автор

Voice is clear and loud like lady army officer 👍👍👍 and concept also clear

Coding-Just
Автор

this is the easiest explanation i found so far

thakurprathiksinghrajput
Автор

thank you so much mam, your concept in this particular problem is easily understandable

ayush.
Автор

Give graphical explanation for "pwwkew"

_SANJAYM
Автор

Using List time complexity is O(n2) .. replace with Set to have O(n) time complexity
Correct me if wrong. Thanks

rupeshpatil
Автор

Try for this test case :'abcbad'

saikiran
Автор

Todo code ko zoom out bhi ker diya kero Madam 🙏

Ford_