Longest Substring Without Repeating Characters | C++ | LeetCode | 3 Approaches Explained | Amazon

preview_player
Показать описание
Given a string, find the length of the longest substring without repeating characters.

Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.

Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

***Correction in Brute Force Method RETURN STATEMENT

return m? m : len; //If m is still 0 (due to no repeated characters in the string), return the default value of len (=1)

Thanks Phuc Lam, for pointing this out :)

#decodethecodewithakm #ankitkumarmishradtc #decodethecode #easeintocodingalongwithcomplexities

You can follow me on the following social media sites:
Facebook:

Instagram:

LinkedIn:

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

There's another mistake in the brute force method. Suppose you have a string say "abbb". In the brute force method when i=0, m=4, since 'a' never repeats again. However the substring "bbbb" has all repeating characters

MrApplefreaker
Автор

I don’t think the brute force actually works because if there is no repeat in the string you will always return count which is 0. You never enter the if condition to update count.

ryanlam
Автор

Thanks for the efforts. The sliding window code doesn't work when the input "pwwkew", it returns 4 while the output should be 3

EngMohannad
Автор

please do something about static sound!

rahulveersingh
welcome to shbcf.ru