Can you please help in solving the question - 68. Text Justification. There is no explantation even in leetcode, please. Thank you so much for your valuable videos.
Thank you, This would be my approach: import sys def min_sub_array(target, nums): l = 0 r = 1 if target == nums[l]: return 1 total = nums[l] + nums[r] min_len = sys.maxsize while r >= l and r < len(nums): if total == target: min_len = min_len if min_len < r-l+1 else r-l+1 l = l+1 r = r+1 total = sum(nums[l:r + 1]) elif total > target: min_len = min_len if min_len < r-l+1 else r-l+1 l = l+1 total = sum(nums[l:r+1]) else: r = r+1 total = sum(nums[l:r+1]) min_len = 0 if min_len == sys.maxsize else min_len return min_len
@neetcode sir .in this question follow up is to solve this by binary search....please help me to do using binary search...atleast please give a hint how we can solve using binarysearch..please
I don’t think that works. Imagine the input array in example 1 was [2, 3, 1, 2, 3, 4] instead (basically just swapping the last two elements). If you jumped to the largest element, you’d hit the end of the list before ever reaching the max. It’s possible to add a conditional to check both sides of the max, but that might run into issues if you had an input like this: [2, 3, 2, 1, 1, 4, 1]
Yes, it's still contiguous. A subarray is by definition contiguous. You can test it on LeetCode too. If they accepted non-contiguous elements then the solution to nums = [5, 1, 2, 3], target = 7 should be 2. Because [5] and [2] sum to 7. But their expected answer is 3 because [5, 1, 2] is the only contiguous subarray that sums to >= 7.
hey thanks for the great video, but I'm having a problem. I implemented the similar idea with python then submit, but it got error with the input of [1,2,3,4,5]. It said expected "3" but I dont see any valid window with that size. Can anyone help, thanks!
Why would it be O(N^2)? The right pointer iterates through the entire array doing O(1) work each time. That's O(N). And the left pointer also iterates through the entire array in the worst case, doing O(1) work each time. That's also O(N). So the overall time is O(N).
Good day sir , I appreciate all the work u are doing , pls sir can u pls look at the increasing in order search tree question 897, I’m having a hard time understanding the recursion process used ,thank u sir
Practice. Do multiple sliding window problems and you'll be able to recognise the pattern. These are PHD level dissertations and you can't come up with your own if you haven't done similar problems before.
This is probably the best Leetcode channel on the internet. Thank you so much for the invaluable content. Your drawing explanations are gold!
after watching so many problems done by u. For this problem i've came up with exactly the same solution
Please do a video on the follow up question of this question: what do we do if there are negative numbers in the array. Thanks.
Many thanks to you sir, you're actually helping a lot of people by solving these questions
This guy is absolute Legend and has ability to make complicated problems look easy! Thanks man :) Keep up the good work.
Probably the most precise explanation. Thanks a lot. Keep posting.
Much appreciated, the explanation is way better than any Leetcode solution provided.
What a coincidence, I was just solving the same problem on Lintcode !
Thanks a lot for the upload, I have an upcoming google interview
Best of luck
Good luck!
lintcode?
I thought this question had some trick in it but it's only a sliding window
Great explanation ❤
i was kinda confused on why you were not using if statement thanks for clearing my doubt you are a legend
This was a pretty complicated problem. Thanks a lot for helping me understand it.
Really feel relaxed when i am looking for a solution of a problem on youtube and find your vedio ❤❤
Every time when I hear "Hi everyone welcome back" I'm excited!!!
mate you are not a real person
Thank you, I was struggling to this question until I found your video
expend right until success, shrink left until fail
Love you NC, best coding channel ever...
You are a good person, helping us in programming 😊.
How do you build such algos ?
Plz give us a path to stick to master DSA 🙏
Love your videos. They're so helpful. Always leave more informed and with one more approach than before playing your video.
1590 is basically this problem but needs to be equal not greater than
What would be the solution if there would be negative numbers in the array?
so many people are helped because of you
my first comment ever on YT, you are an inspiration. please keep creating such awesome content !! you are helping community, thank you !
What do you make of the follow-up question, which asks us to come up with a worse solution that the sliding window one we already came up with?
daily one problem from your channel,,thats the challenge I took
great... You makes coding fun
Solving this on my own took way too long :)
When neet say things like: "well this is easy solution" or "this is just a standard xyz algo" just makes a dumbhead like me feel even dumber.
Beautiful solution
Gracias por el video otra vez! Gran ayuda que esta poniendo en youtube!
Please create a playlist for DSA and DP in python beacause there isn't any on RUclips yet.....it will help thousand of ppl.
Can you please help in solving the question - 68. Text Justification. There is no explantation even in leetcode, please. Thank you so much for your valuable videos.
This solution (optimized) was pretty easy to come up with. But can you make a video on the follow up of this question i.e. do it in O(nlogn)
I was thinking about an algorithm that would leverage sorting the nums in reverse order and I kinda feel like it could be possible
Hi neetcode! Could you post a video on Knight Dialer? It would mean a lot! Thank youu
Thank you,
This would be my approach:
import sys
def min_sub_array(target, nums):
l = 0
r = 1
if target == nums[l]: return 1
total = nums[l] + nums[r]
min_len = sys.maxsize
while r >= l and r < len(nums):
if total == target:
min_len = min_len if min_len < r-l+1 else r-l+1
l = l+1
r = r+1
total = sum(nums[l:r + 1])
elif total > target:
min_len = min_len if min_len < r-l+1 else r-l+1
l = l+1
total = sum(nums[l:r+1])
else:
r = r+1
total = sum(nums[l:r+1])
min_len = 0 if min_len == sys.maxsize else min_len
return min_len
can we check if r-l+1= 1 inside the while loop and return 1 if that's the case?
What if the array contains all elements greater than the target then wouldn’t the time complexity run in O(n^2)?
Isn't brute force solution's time complexity is O(n^2 logn) /O(n^3) ?
How do you do it so easily dude. I spent hours clueless trying to come up with stupid solutions.
@neetcode sir .in this question follow up is to solve this by binary search....please help me to do using binary search...atleast please give a hint how we can solve using binarysearch..please
amazing! love it
Is there a faster approach where you start at the index of the largest number in the list rather than the first?
I don’t think that works. Imagine the input array in example 1 was [2, 3, 1, 2, 3, 4] instead (basically just swapping the last two elements). If you jumped to the largest element, you’d hit the end of the list before ever reaching the max. It’s possible to add a conditional to check both sides of the max, but that might run into issues if you had an input like this: [2, 3, 2, 1, 1, 4, 1]
@@zolopane117 yeah I was thinking you’d expand outward from the largest item.
First here today ig. Thank you so much for these videos .
what if the array contains negative too?
how can we do this with one passage through array??
Very nice content as usual :3 !!
When are we getting a series for System Design ?
Hopefully next month!
wait, they got rid of the "contiguous" part on the problem. Is it still contiguous?
Yes, it's still contiguous. A subarray is by definition contiguous.
You can test it on LeetCode too. If they accepted non-contiguous elements then the solution to nums = [5, 1, 2, 3], target = 7 should be 2. Because [5] and [2] sum to 7. But their expected answer is 3 because [5, 1, 2] is the only contiguous subarray that sums to >= 7.
What software do you use to draw? And how do you record it?
How many problems you solve per day ❤️
he said at least one, but sometimes more depending on the day.
hey thanks for the great video, but I'm having a problem. I implemented the similar idea with python then submit, but it got error with the input of [1,2,3,4,5]. It said expected "3" but I dont see any valid window with that size. Can anyone help, thanks!
oh it's greater than or equal to
@@trungduong8225 lol thanks dude..
i feel dumb now
Can anyone explain why its not O(n²)
Same question here.
Why would it be O(N^2)?
The right pointer iterates through the entire array doing O(1) work each time. That's O(N). And the left pointer also iterates through the entire array in the worst case, doing O(1) work each time. That's also O(N). So the overall time is O(N).
Can anybody help me with understanding the complexity of the solution coded here?
Good day sir , I appreciate all the work u are doing , pls sir can u pls look at the increasing in order search tree question 897, I’m having a hard time understanding the recursion process used ,thank u sir
Is this a joke. how am i supposed to come up with it during the interview. anyway, great video as always.
Practice. Do multiple sliding window problems and you'll be able to recognise the pattern. These are PHD level dissertations and you can't come up with your own if you haven't done similar problems before.
any one wants to practise please comment
bruh we can almost hear you, please decrease your voice volume a bit more