We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!! Questions you might like: ✅✅✅[ Tree Data Structure ] : ruclips.net/p/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls ✅✅✅[ Graphs Data Structure ] : ruclips.net/p/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C ✅✅✅[ December Leetcoding Challenge ] : ruclips.net/p/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA ✅✅✅[ November Leetcoding Challenge ] : ruclips.net/p/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e ✅✅✅[ August Leetcoding Challenge ] : ruclips.net/p/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe ✅✅✅July Leetcoding challenges: ruclips.net/p/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC- ✅✅✅June Leetcoding challenges: ruclips.net/p/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG ✅✅✅May Leetcoding challenges: ruclips.net/p/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e ✅✅✅Cracking the Coding Interview - Unique String: ruclips.net/p/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE Struggling in a question?? Leave in a comment and we will make a video!!!🙂🙂🙂
C++ Code : class Solution { public: // Sliding Window // TC : O(n) // SC :O(min(m,n)); m - length of charset int lengthOfLongestSubstring(string s) { int n = s.size(); int maxLen = 0; // Store last seen index of each character unordered_map charIndex; int start = 0; for (int end = 0; end < n; end++) { if (charIndex.find(s[end]) != charIndex.end()) { start = charIndex[s[end]]; maxLen = max(maxLen, end - start); } charIndex[s[end]] = end; maxLen = max(maxLen, end - start); } return maxLen; } };
We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!!
Questions you might like:
✅✅✅[ Tree Data Structure ] : ruclips.net/p/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls
✅✅✅[ Graphs Data Structure ] : ruclips.net/p/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C
✅✅✅[ December Leetcoding Challenge ] : ruclips.net/p/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA
✅✅✅[ November Leetcoding Challenge ] : ruclips.net/p/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e
✅✅✅[ August Leetcoding Challenge ] : ruclips.net/p/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe
✅✅✅July Leetcoding challenges: ruclips.net/p/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC-
✅✅✅June Leetcoding challenges: ruclips.net/p/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG
✅✅✅May Leetcoding challenges: ruclips.net/p/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e
✅✅✅Cracking the Coding Interview - Unique String: ruclips.net/p/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE
Struggling in a question??
Leave in a comment and we will make a video!!!🙂🙂🙂
it was quite helpful
Thank you!!
"gbcjkancb" in this case, the output shows "jkanc" not "jkancb" because 'b' is already in the map. don't you need to update map?
really hard to understand please provide more explanation
ruclips.net/video/vHZjMkrSc2M/видео.html
nice
Thanks Pawanpreet!! 🙂
Ek no.🙂
👍👍
Please code in c++ language instead of Java
C++ Code :
class Solution {
public:
// Sliding Window
// TC : O(n)
// SC :O(min(m,n)); m - length of charset
int lengthOfLongestSubstring(string s) {
int n = s.size();
int maxLen = 0;
// Store last seen index of each character
unordered_map charIndex;
int start = 0;
for (int end = 0; end < n; end++) {
if (charIndex.find(s[end]) != charIndex.end()) {
start = charIndex[s[end]];
maxLen = max(maxLen, end - start);
}
charIndex[s[end]] = end;
maxLen = max(maxLen, end - start);
}
return maxLen;
}
};