Longest Subarray with sum K | Brute - Better - Optimal | Generate Subarrays

preview_player
Показать описание
Notes/C++/Java/Python codes:

Problem links.

We have solved the above problems, and we have gone from brute force and ended with the most optimal solution.

You can follow me across social media, all my handles are below:

0:00 Introduction of course
Рекомендации по теме
Комментарии
Автор

Let's march ahead, and create an unmatchable DSA course! ❤

Timestamps pleaseeee

Use the problem links in the description.

takeUforward
Автор

I've been watching this lecture for the last two days, and it was so frustrating that I couldn't understand the concept, even though Raj Bhaiya explained it thoroughly. After putting in about 7-8 hours, I finally understood what was holding me back. Here's what I've learned:

1. map_name.find(value)-> This function returns an iterator to the element with the key `value` if it is present in the map. If the key is not found, it returns an iterator to `map_name.end()`.

2. map_name.end()-> This function returns an iterator one past the last element of the map. If your map has a size of 4 (indexing from 0 to 3), `map_name.end()` will give you an iterator representing index 4, which is beyond the last element.

3. if(map.find(value) != map.end())-> This line was a real pain in my ass so basically this line checks whether the key `value` is present in the map. If `map.find(value)` does not equal `map.end()`, it means the key is found in the map.similarly, if `map.find(value)` equals `map.end()`, the key is not present in the map.

Understanding this line was crucial for me. The `.find()` function returns an iterator to the element if it is present, or `map.end()` if it is not. So, the condition `if(map.find(value) != map.end())` essentially means, "if the key `value` is found in the map."

If you've read this far, all the best, buddy! I was literally crying inside after watching the video again and again, but if a noob like me can understand it, you will definitely nail it. Haha. Thanks, Raj Bhaiya.

ashutoshbhardwaj
Автор

When Striver says no one will teach you in such depth, he means it

viveknandan
Автор

To all those whose mind are like " shyd coding is not for me" after seeing this question
Take my one advice am the one solving it from 11 :am in the morning and understood it at 7 20 pm of evening
I between my mind qas like chod de "pr bhaiya chodna hi toh nhi hai tabhi toh smjega"
So give yourself a shootout and say striver bhaiya i will play you once more and play it back to back even if you have watched for 100 times play it slowly took a pen copy and try to understand what bhaiya is saying 🎉🎉

Awanderer
Автор

I am following your playlist for DSA. I got subarray of string related problem in my JP Morgan interview. I have explained the approach as you taught. It was quite simple for me to explain the approach as I had watched your this video.. Thank you so much sir you are doing very well.

JustExploreByTravel
Автор

TIMESTAMPS
0:00 Intro
0:43 Problem Explanation
3:37 Brute force approach
10:50 Better approach (Both positives + negatives)
26:57 Time complexity of Hashing based better solution and why its best for both positives and negatives
28:55 Optimal solution (positives only)
37:52 Time complexity of two pointer based optimal solution

Piyushraj
Автор

You are helping families not individuals. Thanks for this.

afzhalahmed
Автор

Please keep this series continued. Brilliant work Raj. I am speechless. An if anyone reading this, and you have a difficulty understanding, don't give up, just watch 2-3 more times, you shall understand, trust me.

utsavseth
Автор

That hashing one went above my mind maybe need to watch it again

gunslingerlynx
Автор

Those who understand the beauty of ur optimal codes, will agree, ALL UR LEC.S ARE PURE GOLD.
U are a gr8 GURU .... sharing such exceptional lec.s for free is superb SERVICE FOR MANKIND.
U are empowering youth ... making difficult topics look like easy ....
u explain everything so easilty ... study looks like fun when u teach.
Codes can revolutionise the world ... can take us to distant planets....
Codes are like miracle ... the way incredible creation like AI is developed .... Sw Er.s are next Gen soldiers of nation.
They can fuel engine of growth and contribute in development of nation and growth of humanity.
U r doing exceptional work ... Thank for God bless u ... Tc.

eklavyak
Автор

Thank you striver for this ultimate course, I was trying from many days and searching to starts DSA, and this course made me do it
Today day 15 😅

AbhishekPandey-djeo
Автор

Outstanding Explaination...

I cant able to understand by watching this video even 2 times. It doesnt mean, striver didn't explained well.

He explained very well.

so, people who are not able to understand it well, try to watch it again and again...!

Dont search for other videos for this question, and if you even search, I will assure you that, you cant able to find better explaination than this..!

Striver, Thank you so much...!

Srinivasssssss
Автор

Had to watch it twice to understand it like 95% but did understand it.
Really impressive stuff!

tahaansari
Автор

Absolutely brilliant. Haven't seen anyone else on YouTube explaining any dsa problem with this much clarity.

DK-oxze
Автор

Understood !! Both Interviewer And Me Are Super - Duper Impressed !!

tanishqbansal
Автор

In bruteforce approach we can also add the condition to reduce the number of operations that if(sum >K)break from the inner loop if the array contains positive elements only

bhanupratapjaiswal
Автор

The best video till now I have seen for this problem . 41 minutes explanation for a single problem is just a next level thing.

arunavabanerjee
Автор

After spending entire 2 days on this I have finally understood the lecture and the concepts of subarray. It was not easy at first but after spending all the time I came across a comment that saying "It wont be easy, but it will be worth it" on this I can say that It was definitely worth it!! The point is I still don't know if DSA is important or not or any other blah blah. But the efforts I am willing to give to learn it is what amazes me. If a guy like me can understand this you can too!! Don't give up!!

adityalawande
Автор

Amazing!!💗💗 Also, we can further trim down the code provided in 26:46. If we intialize our HashMap with map.put(0, -1), we can skip checking the condition of if(sum==k)

hritikshah
Автор

This man is a god straight from heaven for programmers. The Clarity he has in his explanation is absolutely Amazing! Never seen a guy who is so passionate teaching DSA. Love you Raj Bhai! ❤

vigneshpandi