Longest Substring Without Repeating Characters | Amazon
Фильм және анимация
Check our Website:
In case you are thinking to buy courses, please check below:
Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------------------------------- Check out website: In case you are thinking to buy courses, please check below:
Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------------------------------- I have decided to make a free placement series comprising of video lectures(C++ and Java) on the entire SDE sheet.. ✅(bit.ly/takeUforward_SDE) ..
✅Use coupon-code "TAKEUFORWARD" for getting 10% for all GFG courses: bit.ly/tuf_gfgCourse
✅Entire Series: bit.ly/placementSeries
✅Problem link: leetcode.com/problems/longest...
✅ Kadane's Link: • Maximum Subarray Sum |...
If you appreciate the channel's work, you can join the family: bit.ly/joinFamily
Thumbnail Creator: / rikonakhuli
✅ Striver's Linkedin Profile: / rajarvp
✅ Instagram: / striver_79
Connect with us: t.me/Competitive_Programming_tuf (Use Link in Mobile only, if not works search "takeUforward" in telegram)..
#dsa #leetcode #placements
Пікірлер: 235
Understooooooooooooooood? . Instagram(connect if you want to know how a SDE's normal life is): instagram.com/striver_79/ . . If you appreciate the channel's work, you can join the family: bit.ly/joinFamily
@MANOJSHARMA-tw8gg
3 жыл бұрын
Aapki life normal toh nahi hai Supernatural powers 🔥😀
@sahukarinaveenkumar3188
3 жыл бұрын
for moving left pointer why you are taking Math. max( lastoccurence+1, left)? Got confused with this 😒
@learnwithme7750
3 жыл бұрын
yes please tell this
@aryangupta867
3 жыл бұрын
I have a genuine doubt. Like while using the below code it worked on GFG int longestUniqueSubsttr(string S){ int left=0; int right=0; int n=S.length(); int maxlen=0; vectormp(256,-1); // unordered_mapindex; while(right
@Sweety-rx8zq
3 жыл бұрын
Why O(2N) ? Can someone plz explain...
10:27 Space Complexity should be O(1) because the set can contain at max all the 26 alphabets. It won't increase more with the size of data.
@takeUforward
3 жыл бұрын
O(256) to be precise, thanks for the correction.
@AbhishekKumar-vr7sh
2 жыл бұрын
@@takeUforward and also the time complexity of the brute force soln would be O(n*256) as we break from the inner loop as soon as we encounter duplicacy which in the worst case won't exceed 256.
@aysams2
Жыл бұрын
why would it be O(1). I ddin't understand
@deepakpallavalli3513
11 ай бұрын
@@aysams2constant space irrespective of length of the string
@studyafa7159
10 ай бұрын
Can some one Please summarise what would be the Space complexity ..? O(1) Or O(n)
Striver, your explanation is best, our college teachers never took such pain to explain a certain concept. Thank you so much striver!❤️
Bro I truly Love ur Videos . I love the way you explain and u r such a honest person . I started doing Competitive programming because of ur information on how imp is CP to get high position in tech community. I truly loving the CP as I move deep in the problems
was confused as to how you were passing in a char as an input for the vector. for anyone wondering when you pass in a char when an int is expected in a vector array, the char is converted automatically to its ascii value which is an int i.e mpp['a'] becomes mpp[97] as a ascii=97. also, the vector is being used as a hashmap with key: value being index:value.
*Code for 2nd Approach* int Solution::lengthOfLongestSubstring(string A) { int n = A.length(); int maxi=INT_MIN;; int i=0,j=0; unordered_sets; while(j
@neerajgarg9096
2 жыл бұрын
T.C- O(2N)*
@raghavgupta00
Жыл бұрын
but it gives TLE when you run this code for the question on gfg in worst case its O(N^2) @striver
It was so much easy explanation by you that i understood the whole concept in just single go and didn't require to see the code.
I don't know why your explanation to the problem is so good.. I have done this problem but I really understood it with your explanation thanks
one correction, the space complexity of this problem is O(1) not O(n) because even if we include all ascii characters, we only have 256 and this 256 does not change with respect to the size of problem, hence O(1) Thanks for the content bro, from down south!
@omprakashhardaha7736
2 жыл бұрын
Nice 🤘 You u got placed
@sunilgrover4178
2 жыл бұрын
@@omprakashhardaha7736 What are you trying to say?
@omprakashhardaha7736
2 жыл бұрын
@@sunilgrover4178 😂😂 I ask him Ki place hua ya nhi Heavy English 😃
@sunilgrover4178
2 жыл бұрын
@@omprakashhardaha7736 Achha 😂
@omprakashhardaha7736
2 жыл бұрын
@@sunilgrover4178 😅
This is very good explanation for the problem. Actually this is lc medium problem but the explanation of striver made it look like an easy problem
This question was asked in lot of my interviews , Thank you :)
@aniketmasram6500
3 жыл бұрын
Can u tell Which interview ?
@curiocity4642
3 жыл бұрын
@@aniketmasram6500 got asked in my zoho interview last week
@kratitamrakar4779
2 жыл бұрын
But it doesn't pass all the test cases.
@pranavpatki
2 жыл бұрын
@@kratitamrakar4779 It passes
Thanks A bunch bruh for this series though I dont need it now but i came here to support your video. Thanks again for ur guidance ✌
This solution is sooo well explained. thanks a lot!!!
Man. Screw them who criticize you. Yeh tho bawaal hai. I never understood such difficult sum so easily. Now with the approach that you said i can code it very easily. Thank you very much. You should be reaching to the masses of computer science students globally. Greatly appreciable
you're doing a wonderful work, sir!! thanks!!
previous videos so good, mostly figured this out on my own 💕
u are explaining better day by day, video after video👌👌
@takeUforward
3 жыл бұрын
Thank you so much 😀
Probably the best explanation for this problem, dont know why some people have disliked this video !
@takeUforward
3 жыл бұрын
Let them, no issues :)
I love your videos bro becoz your videos contain naive and optimal along with intuition ,so I love your videos bhaiyya...thanks a loooooooooooooooot.
UNDERSTOOD... !!! Thanks striver for the video... :)
can anyone explain how that vector mpp(256,-1) is working as a map??
@EntEduRealm
2 жыл бұрын
kzread.info/dash/bejne/qHyOzK-korbJYrA.html
Best explanation ever No one can explain better than u
your explanation is wonderful
the implementation part is more attractive than the logic itself !!
Superb shifting of l to direct next position and even superb thing is we don't have to remove the intermediate characters from map instead we just have to check whether intermediate char is present in our window or not. This thing was so beautiful. And this is actually called as optimization.
I really love this series. I'll be always thankful to Striver :)
Thanks for clearing the doubt striver.
Yes bhaiya, Understood. You are doing a really great job, bhaiya. We are really really grateful to you.
I wonder how can a person can get this solution intuition using map ! amazing explanation bro!
this is fabulous! you are awesome! thanks for the video!!!
Very interesting explanation. I am a beginner-level in algorithms. As I am learning, I want to know the theory behind your approach in solving this problem 🙏
thank you sir, this helped me understand it very clearly
solution is very well explained thanku bhaiya
Love your content bro...keep up the good work 👍👍👍
Awesome Explaination!🔥
How do you solve using kadane's algo?can anyone provide solution?
Great explanation .... thank you ☺️
THe space complexity should be O(26) i.e O(1) because at max map size can be 26 not more than that
if we use set, it will insert in ascending order and if we use unordered it will take randomly
Can anyone help me understand why O(2*N) complexity for the second solution even when for every outer loop there is an inner loop which will get used when a repeated element appears.
@tahaansari5621
2 жыл бұрын
There's only one loop and O(2N) is the worst time complexity when u would have to move your left index till the end of the array, one by one. So, u would visit each elements exactly twice.
i am getting an error for "au" input the correct output should be 2 but my answer giving me 1 can't figure out the problem
Thanks a lot STRIVER !
Although he told the whole soln using map but in the code vector is used instead of map.Can anyone give some clarity on that?
@take U forward bro if we want to print the string along with the length and if multiple print all then how can we approach? please help :)
@loserfruit9663
3 жыл бұрын
You can use substring function in between
amazing explanation!!
Nicely explained striver!!!!
In the map approch why not clear map if we see a repeated value, cause whole substring before the repeating character Is waste.
last approach was just lit🙌
Good Explanation #programmingsolutions
Understood. Easy explanation
classic question , soooooper classic explaination
In an example like bbbbb won't both left and right pointers move n times each then the worst case is still O(2n), though, for many test cases, this approach is more optimized than the previous one? Correct me if I am wrong.
@rickk3300
Жыл бұрын
Exactly!! in an example like "bbbb", the time complexity of the final approach will go upto O(2N). I had this doubt too.
Amazing Explaination 😀
Amazing content brother, can you tell which software you use to teach? it would be really helpful.
@takeUforward
3 жыл бұрын
Wacom tablet and nothing else.
Very Well explained bhaiya!!!
"if (mpp[s[right]] != -1)" you don't need to check this condition as by default is -1 and you only update left if it has greater value than that and min of left is 0
TOO GOOD EXPLAINATION BRO
Hello @Striver bhaiya, I want to ask that, is following the SDE sheet enough for coding rounds of companies ? I'm not talking of the coding interviews, I'm asking for the first online coding test which takes place in all the companies. Please reply, thank you.
@sundrammishra4757
3 жыл бұрын
Hi Sounak , I am quality assurance engineer working in a service based company. This SDE sheet is for those who have done basics of any programming language . You can go on hackerrank and there is a seprate block for interview preparation there are only 69 challanges if you will do them it would be sufficient to crack coding round.
@mickyman753
3 жыл бұрын
did you got any answer to your question ,if yes please share
Should the TC not be O(nlogn) as for each element we see if it is in a set? 10:09
@arvindroshaan8644
Жыл бұрын
It is actually O(nlog256)=O(n) as the maximum size of set is 256 (extended ASCII)
Woah.. third approach 🔥🔥🔥
Hello bro, Suppose the array contain all duplicates elements(Ex: {b, b, b, b, b}) then at time the time complexity of last approach goes to O(2N) ??
@tanmaysatsangi131
2 жыл бұрын
I have one more question, after saw the comments should I consider space complexity is O(1) or O(N) ??
@aaravgulati2
10 ай бұрын
1. yes 2. O(1)
Well Explained
Instead of the set we can also take a dictionary (python) or hash map and emulate the same, In this case, we do not have to move left pointer 1 by 1 but instead, we can check from the dictionary, how much we need to move the left pointer.so, we can directly write this.
@rajavikramaditya2536
3 жыл бұрын
that approach has been explained..
@gauravidesigns
3 жыл бұрын
@@rajavikramaditya2536 I know you have explained it .I just stopped at when you were using set and the I used map instead of set.I then watched your video furthur .thankyou sir for an awesome explanation
@magicmagus1459
2 жыл бұрын
But I think it might not work with hashmap bc take example of “afbcb”....once right pointer gets to position 4...u simply can’t move left pointer to position 3....hashmap still contains letters ‘a’ and ‘f’ which need to be removed from Hashmap...how will u remove that without moving left pointer one by one using a set
How is the better approach O(2N) and not O(N^2).It has a nested while loop which increments the left pointer.
@monikaraut5266
Жыл бұрын
Yes, I too think the same
@priyanksinha8152
Жыл бұрын
becuase the while loop is never running n times it will just run till there is no duplicate in the substring
Nice explanation.
ty
nailed it!!
we can also we unordered hashmap as the insertion of char will less time and will be eff then this solution edit okay i should have watched the video first llol
Thank you so much bro!!!!!!!!
I dont know hashing or hashmaps can you please tell me from where to learn them first?
@EntEduRealm
2 жыл бұрын
kzread.info/dash/bejne/qHyOzK-korbJYrA.html
yes ,understood ...............................
Understood thanks
def Solve(string): seen = {} longestLength,i,j = 0,0,0 while j if string[j] in seen: i = max(i, seen[string[j]]+ 1) longestLength = max(longestLength,j-i +1) seen[string[j]] = j j += 1 return longestLength
can anyone plz gimme the link of the docs?
#FEEDBACK If u could display codes in Python in your upcoming videos it would be much help to Python faternity as well.
@takeUforward
3 жыл бұрын
For that I will have to learn Python in deep, I only know basic syntax :|
Thank You Striver
Thanks a lot :)
Great video 🔥🙏
I didnt get why we use max(left, mpp[s[right]+1) instead of only mpp[s[right]+1......... plz explain, m stucked here only, apart this I understood everything
@manvikarya725
3 жыл бұрын
Because it is same as writing if(left
@prahaladsinghtomar3081
3 жыл бұрын
@@manvikarya725 he is asking as how mpp[s[right]]+1 can lie on left of left
@prahaladsinghtomar3081
3 жыл бұрын
try your code on "abba" you will find the reason
@subbucs5674
3 жыл бұрын
@@prahaladsinghtomar3081 I think it will be always left = mpp[s[right]] + 1, In the current window, left is left-most index. So, all elements in the current window will have their index >= left. Hence, it is not possible to have an element at left of left. Please correct me if I am wrong.
give code of all the approaches plz
Bhaiya can you please complete the Sliding window playlist from A-Z sheet
great explanation
yep
Understood.
can someone give the code for second method
Bhaiya optimal sol. me to space complexity O(1) nhi hogi bcoz isme to ham fixed vector of size 256 use kr rhe ha ?? Plzz answer
@takeUforward
3 жыл бұрын
Hn 256 is considered almost constant ..islie hi.. since 26 lowercase letters are there, hence you can actually think at max 26 size..
@AB-tp9eg
3 жыл бұрын
@@takeUforward ok thanks bhaiya, so I will explain constant space complexity of this optimal sol. in interview instead of O(n)
Thank you striver bhai
Understood !
Thanks bro
Bhai i am learning c language from past 6 months but i am not able to do question on geeks for geeks should I buy an course from any platform
@ankitpandey-pg1yn
3 жыл бұрын
Bhai pattern wale aate hai pr problem recursion se ho rhi geeks for geeks mein question nhi ho rhe
@hmmmm4193
3 жыл бұрын
Do hackerrank questions first. They are easier than gfg questions. Do 30 Days of Code and Problem Solving topic from HackerRank.
Great explanation
and isn't the first algorithm O(n^2) ?
Me set and queue use krke tezz bnn rha tha!! apne aukat yaad dila de! 2nd approach kudos!
Nice explanation
i could not understand how we can recognize particular character is present in vector or not..bcz vector is of type int not char..anyone? plz help
@takeUforward
3 жыл бұрын
Converts into ascii and then comparison is done..
@dhanashreegodase4445
3 жыл бұрын
@@takeUforward thanks
if we use 256 characters vector then space complexity is constant so its equivalent to O(1) I think.
@samarpanharit4268
3 жыл бұрын
Nice
@takeUforward
3 жыл бұрын
Yes :)
This code is showing time limit exceeded on leetcode plz help
Understooooooooooooooood!
Amazing bhai🙏
Understood