waiting for your explanation on the biweekly contest brev, that one is so hard
@Alpha-Code3 күн бұрын
Probably won't do that one, maybe sometime mid week. Don't have the time right now.
@tzuilee5883 күн бұрын
@@Alpha-Code sure no pressure man, been really enjoying watching your explanations
@GeethaSriChekka3 күн бұрын
Increase the font size .It is too small
@tzuilee5883 күн бұрын
well explained, thanks
@ShubhamSharma-sf8wk4 күн бұрын
Most simple solution ever, thanks for this man
@MSDHONI-ne3uq5 күн бұрын
Congratulations man, U got 365 🔥, 1 year consistency is not everyone's cup of tea, need motivation like you, Do more videos like these on java ☺️🌟
@ShubhamSharma-sf8wk6 күн бұрын
Definitely not a medium problem
@Alpha-Code6 күн бұрын
@@ShubhamSharma-sf8wk facts
@dianarehan75997 күн бұрын
keep going
@qulinxao7 күн бұрын
more simple parse '('+formula+")" as: for each name we push to stack {name:1}; for each number we mult all values of hash in top of stack; for each ( we just push it to stack for each ) we merge all hash on from stack from top until on top is ( then remove ( and push this merged hash it more simple and shorter
@dianarehan75998 күн бұрын
hey dude i guess you put the wrong java solution on github
@Alpha-Code8 күн бұрын
thx foxed
@levelup20148 күн бұрын
Can you talk about how you would self study after graduating codesmith? How long after you graduated did you feel "confident" in your ability to do technical interviews? Can you talk more about how you would prepare for those, like how many leetcode Q's should you complete & how to incorporate system design
@Alpha-Code7 күн бұрын
What I did for self study was do a bunch of courses in React, Next Ss, etc. LeetCode q's to complete probably depends on your level and what you are interviewing for. System design I'd prolly just ignore cause you won't do well without work experience. I just focused on high number of apps and studying whatever I was interested in at the time. I felt pretty confident in my technical interview ability but the bigger issue was my ability to pass phone screens imo.
@MSDHONI-ne3uq8 күн бұрын
Thankyou
@shreyabajaj45888 күн бұрын
Can you explain why this code is giving TLE at 328 no test case ... /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public String getDirections(TreeNode root, int startValue, int destValue) { TreeNode head=LCA(root,startValue,destValue); String start=Start(head,startValue); String end=Start(head,destValue); String ans=""; if(start!=null){ for(int i=0;i<start.length();i++){ ans+="U"; } } if(end!=null)ans+=end; return ans; } private TreeNode LCA(TreeNode root, int st,int end){ if(root==null)return null; if(root.val==st|| root.val==end)return root; TreeNode left=LCA(root.left, st, end); TreeNode right=LCA(root.right, st, end); if(left!=null && right!=null)return root; else if(left!=null)return left; return right; } private String Start(TreeNode head,int end){ if(head==null)return null; if(head.val==end)return ""; String left=Start(head.left,end); if(left!=null)return "L"+left; String right=Start(head.right,end); if(right!=null)return "R"+right; return null; } }
@Alpha-Code8 күн бұрын
just reading it briefly I think its cause ur doing string concatenation with the L + left and R + left. I spoke about this in the video briefly, if you do string concatenation across a tree that is very unbalanced you will get O(n^2) time complexity. That's why you need to build up the string as you go with a builder or array then store it once you find the 2 values you are looking for to reduce to O(n).
@nurtorekelesov428610 күн бұрын
great work, thanks for the video
@MSDHONI-ne3uq10 күн бұрын
Hats off Bro, tqsm
@rashidmahmood712110 күн бұрын
love the thumbnail lol
@udhaya848913 күн бұрын
For each problems, please click on the companies tab and show us the companies
@Alpha-Code13 күн бұрын
@@udhaya8489 sure I’ll do that
@vikasg581614 күн бұрын
Clear explanation. Thanks
@storingudemy-yg7xs14 күн бұрын
For some reason my test case isn't passing when i try to submit
@rajan-u6b15 күн бұрын
I was stuck for very long time, then eventually figure out the 'Long', lol
@snehalsrivastava281015 күн бұрын
I was also stuck at the problem where you converted int into long for 30 minutes thankyou
@shreyabajaj458816 күн бұрын
Why didn't u put the sols of weekly contest 405 solution and biweekly contest sols😢
@Alpha-Code16 күн бұрын
I was busy with work stuff this week. Might put up weekly contest solution up later, it wasn't the best one. All the problems were pretty standard and the last one was just basically Word Break Problem with 2 more lines of code.
@MishkatMazumder17 күн бұрын
Best explanation of this problem I have seen so far, many thanks.
@juanmacias592217 күн бұрын
I assumed I was missing a constant time math proof, but I guess simulation is the only way ha
@Alpha-Code17 күн бұрын
There is I think but it's not super intuitive :(
@juanmacias592217 күн бұрын
@@Alpha-Code that makes sense. ha thanks for the video. :D
@rajan-u6b18 күн бұрын
this kind of question is quite frequent in LC contest, I just use flag variable for direction and simulate
@jantrollan335819 күн бұрын
Very good explanation
@GelfandTransform24 күн бұрын
Very nice explanation! And cool art in the thumb nail. I need to think about why, when generating a spanning tree, the method of first choosing type 3 edges when possible, and then secondarily choosing type 1 & 2 edges, always gives the maximal number of edges that can be removed.
@rajan-u6b24 күн бұрын
only able to solve first 2. thanks for your editorials
@AryanSingh-eq2jv29 күн бұрын
i wrote this code class Solution: def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]: graph = defaultdict(lambda:defaultdict(lambda:float("inf"))) for edge in edges: graph[edge[0]][edge[1]]=edge[2] graph[edge[1]][edge[0]]=edge[2] while(True): shortest={} minHeap=[] heapq.heappush(minHeap,(0,source)) while minHeap: cost,node = heapq.heappop(minHeap) if node in shortest: continue shortest[node]=cost for neighbour,cost_to_neighbour in graph[node].items(): if neighbour not in shortest: if cost_to_neighbour==-1: heapq.heappush(minHeap,(cost+1,neighbour)) else: heapq.heappush(minHeap,(cost+cost_to_neighbour,neighbour)) if shortest[destination]>target: return [] if shortest[destination]==target: for i in range(len(edges)): if edges[i][2]==-1: edges[i][2]=1 return edges l=[destination] pathh=[] def path(node,cost): nonlocal pathh if cost==0: pathh=l.copy() return for neighbour,cost_to_neighbour in graph[node].items(): if cost_to_neighbour==-1: cost_to_neighbour=1 if cost - cost_to_neighbour == shortest[neighbour]: l.append(neighbour) path(neighbour,cost-cost_to_neighbour) l.pop(-1) path(destination,shortest[destination]) flag=True pathh=pathh[::-1] a=10**9 b=10**9 for i in range(len(pathh)-1): if graph[pathh[i]][pathh[i+1]]==-1: a=pathh[i] b=pathh[i+1] flag=False break if flag: return [] for edge in edges: if (edge[0]==a and edge[1]==b) or (edge[1]==a and edge[0]==b): edge[2]=target-shortest[destination]+1 graph[edge[0]][edge[1]]=target-shortest[destination]+1 graph[edge[1]][edge[0]]=target-shortest[destination]+1 break
@AryanSingh-eq2jv29 күн бұрын
it works but gives me a TLE so ig it doesnt really work
@AryanSingh-eq2jv29 күн бұрын
really appreciate it man
@danishtiwari252029 күн бұрын
Great Video and explanation thanks a bunch!!
@margin100pxАй бұрын
Cool thumbnail!!
@rajan-u6bАй бұрын
please don't say problems were that easy😑, love your videos btw, solution for W-403 coming?
@Alpha-CodeАй бұрын
yup uploading now. Hehe sorry.
@rajan-u6bАй бұрын
thanks
@rashidmahmood7121Ай бұрын
Great explanation. Is there any way we can connect? LinkedIn?
@Alpha-CodeАй бұрын
Yeah sure I'll add my LinkedIn to the about page.
@rashidmahmood7121Ай бұрын
I'm a Java coder and I wasn't able to find any KZread channel where I could get solution explanations to daily leetcode problems which led me to breaking my streak many times. I was following a python guy but it was inconvenient to understand the python code and then write the same in java. Thanks to you that you upload videos everyday and now I'm able to solve problems easily.
@Leetneetcode1729Ай бұрын
i do not understand
@Alpha-CodeАй бұрын
:) Lemme know what in particular.
@rostyslavmochulskyi159Ай бұрын
In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of O(logn) for sorting
@Alpha-CodeАй бұрын
Gotcha, I think in Python its also not O(1) for sort but most people write it that way.
@MehdiKhfifiАй бұрын
i don't understand why the left position has to be 1 and not 0?
@tzuilee588Ай бұрын
it doesn't matter if it's 0 or 1, we are binary searching the gap not the array index
@Alpha-CodeАй бұрын
It wouldn't matter, but also if you have enough buckets to put the balls in if it was zero you'd put every ball in the same bucket which wouldn't make sense. You can always put the balls in different buckets and the minimum space between buckets is 1.
@mituldwivedi4469Ай бұрын
i got the time limit exceed through your code , please help me!!
@Alpha-CodeАй бұрын
which one the Java code? They all seem to be working for me so I think it's an issue on your end.
@mituldwivedi4469Ай бұрын
@@Alpha-Code my bad I interchanged the left and right pointers 🥲🥲
@juanmacias5922Ай бұрын
@@Alpha-Code personally I messed up by incrementing/decrementing by one, and not by the middle + or - 1 lol
@sunshinekanika5797Ай бұрын
would sliding windows make it concise or possible that way?
@Alpha-CodeАй бұрын
I don't think you can do sliding windows cause you don't know the range of numbers you can have in the window is the issue. That's why bin search is better.
@shreyabajaj4588Ай бұрын
Great logic!!
@Alpha-CodeАй бұрын
Thanks!
@kevinnguyen4222Ай бұрын
Great video! I knew the last one was a Segment Tree but couldn't figure it out directly. Very smart to pose it as a range sum question. Was missing your vid last week 😆
@tzuilee588Ай бұрын
well explained, thanks man!
@udhaya8489Ай бұрын
I was expecting your video Yesterday
@abhcode7219Ай бұрын
How did you come up with this approach many people are using treemap/priority queue/min heap for it ,how to decide the good one? I personally loved this solution since it is straight forward! Thanks
@Alpha-CodeАй бұрын
Well I realized that I need to know the min value available and can get the rest from there so yeah either min heap or just use hashmap and array since my values never change. Heap better for when your values change instead of static.
Пікірлер
NICE SUPER EXCELLENT MOTIVATED
thanks for the content!
thanks for the content!
great explanation!
waiting for your explanation on the biweekly contest brev, that one is so hard
Probably won't do that one, maybe sometime mid week. Don't have the time right now.
@@Alpha-Code sure no pressure man, been really enjoying watching your explanations
Increase the font size .It is too small
well explained, thanks
Most simple solution ever, thanks for this man
Congratulations man, U got 365 🔥, 1 year consistency is not everyone's cup of tea, need motivation like you, Do more videos like these on java ☺️🌟
Definitely not a medium problem
@@ShubhamSharma-sf8wk facts
keep going
more simple parse '('+formula+")" as: for each name we push to stack {name:1}; for each number we mult all values of hash in top of stack; for each ( we just push it to stack for each ) we merge all hash on from stack from top until on top is ( then remove ( and push this merged hash it more simple and shorter
hey dude i guess you put the wrong java solution on github
thx foxed
Can you talk about how you would self study after graduating codesmith? How long after you graduated did you feel "confident" in your ability to do technical interviews? Can you talk more about how you would prepare for those, like how many leetcode Q's should you complete & how to incorporate system design
What I did for self study was do a bunch of courses in React, Next Ss, etc. LeetCode q's to complete probably depends on your level and what you are interviewing for. System design I'd prolly just ignore cause you won't do well without work experience. I just focused on high number of apps and studying whatever I was interested in at the time. I felt pretty confident in my technical interview ability but the bigger issue was my ability to pass phone screens imo.
Thankyou
Can you explain why this code is giving TLE at 328 no test case ... /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public String getDirections(TreeNode root, int startValue, int destValue) { TreeNode head=LCA(root,startValue,destValue); String start=Start(head,startValue); String end=Start(head,destValue); String ans=""; if(start!=null){ for(int i=0;i<start.length();i++){ ans+="U"; } } if(end!=null)ans+=end; return ans; } private TreeNode LCA(TreeNode root, int st,int end){ if(root==null)return null; if(root.val==st|| root.val==end)return root; TreeNode left=LCA(root.left, st, end); TreeNode right=LCA(root.right, st, end); if(left!=null && right!=null)return root; else if(left!=null)return left; return right; } private String Start(TreeNode head,int end){ if(head==null)return null; if(head.val==end)return ""; String left=Start(head.left,end); if(left!=null)return "L"+left; String right=Start(head.right,end); if(right!=null)return "R"+right; return null; } }
just reading it briefly I think its cause ur doing string concatenation with the L + left and R + left. I spoke about this in the video briefly, if you do string concatenation across a tree that is very unbalanced you will get O(n^2) time complexity. That's why you need to build up the string as you go with a builder or array then store it once you find the 2 values you are looking for to reduce to O(n).
great work, thanks for the video
Hats off Bro, tqsm
love the thumbnail lol
For each problems, please click on the companies tab and show us the companies
@@udhaya8489 sure I’ll do that
Clear explanation. Thanks
For some reason my test case isn't passing when i try to submit
I was stuck for very long time, then eventually figure out the 'Long', lol
I was also stuck at the problem where you converted int into long for 30 minutes thankyou
Why didn't u put the sols of weekly contest 405 solution and biweekly contest sols😢
I was busy with work stuff this week. Might put up weekly contest solution up later, it wasn't the best one. All the problems were pretty standard and the last one was just basically Word Break Problem with 2 more lines of code.
Best explanation of this problem I have seen so far, many thanks.
I assumed I was missing a constant time math proof, but I guess simulation is the only way ha
There is I think but it's not super intuitive :(
@@Alpha-Code that makes sense. ha thanks for the video. :D
this kind of question is quite frequent in LC contest, I just use flag variable for direction and simulate
Very good explanation
Very nice explanation! And cool art in the thumb nail. I need to think about why, when generating a spanning tree, the method of first choosing type 3 edges when possible, and then secondarily choosing type 1 & 2 edges, always gives the maximal number of edges that can be removed.
only able to solve first 2. thanks for your editorials
i wrote this code class Solution: def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]: graph = defaultdict(lambda:defaultdict(lambda:float("inf"))) for edge in edges: graph[edge[0]][edge[1]]=edge[2] graph[edge[1]][edge[0]]=edge[2] while(True): shortest={} minHeap=[] heapq.heappush(minHeap,(0,source)) while minHeap: cost,node = heapq.heappop(minHeap) if node in shortest: continue shortest[node]=cost for neighbour,cost_to_neighbour in graph[node].items(): if neighbour not in shortest: if cost_to_neighbour==-1: heapq.heappush(minHeap,(cost+1,neighbour)) else: heapq.heappush(minHeap,(cost+cost_to_neighbour,neighbour)) if shortest[destination]>target: return [] if shortest[destination]==target: for i in range(len(edges)): if edges[i][2]==-1: edges[i][2]=1 return edges l=[destination] pathh=[] def path(node,cost): nonlocal pathh if cost==0: pathh=l.copy() return for neighbour,cost_to_neighbour in graph[node].items(): if cost_to_neighbour==-1: cost_to_neighbour=1 if cost - cost_to_neighbour == shortest[neighbour]: l.append(neighbour) path(neighbour,cost-cost_to_neighbour) l.pop(-1) path(destination,shortest[destination]) flag=True pathh=pathh[::-1] a=10**9 b=10**9 for i in range(len(pathh)-1): if graph[pathh[i]][pathh[i+1]]==-1: a=pathh[i] b=pathh[i+1] flag=False break if flag: return [] for edge in edges: if (edge[0]==a and edge[1]==b) or (edge[1]==a and edge[0]==b): edge[2]=target-shortest[destination]+1 graph[edge[0]][edge[1]]=target-shortest[destination]+1 graph[edge[1]][edge[0]]=target-shortest[destination]+1 break
it works but gives me a TLE so ig it doesnt really work
really appreciate it man
Great Video and explanation thanks a bunch!!
Cool thumbnail!!
please don't say problems were that easy😑, love your videos btw, solution for W-403 coming?
yup uploading now. Hehe sorry.
thanks
Great explanation. Is there any way we can connect? LinkedIn?
Yeah sure I'll add my LinkedIn to the about page.
I'm a Java coder and I wasn't able to find any KZread channel where I could get solution explanations to daily leetcode problems which led me to breaking my streak many times. I was following a python guy but it was inconvenient to understand the python code and then write the same in java. Thanks to you that you upload videos everyday and now I'm able to solve problems easily.
i do not understand
:) Lemme know what in particular.
In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of O(logn) for sorting
Gotcha, I think in Python its also not O(1) for sort but most people write it that way.
i don't understand why the left position has to be 1 and not 0?
it doesn't matter if it's 0 or 1, we are binary searching the gap not the array index
It wouldn't matter, but also if you have enough buckets to put the balls in if it was zero you'd put every ball in the same bucket which wouldn't make sense. You can always put the balls in different buckets and the minimum space between buckets is 1.
i got the time limit exceed through your code , please help me!!
which one the Java code? They all seem to be working for me so I think it's an issue on your end.
@@Alpha-Code my bad I interchanged the left and right pointers 🥲🥲
@@Alpha-Code personally I messed up by incrementing/decrementing by one, and not by the middle + or - 1 lol
would sliding windows make it concise or possible that way?
I don't think you can do sliding windows cause you don't know the range of numbers you can have in the window is the issue. That's why bin search is better.
Great logic!!
Thanks!
Great video! I knew the last one was a Segment Tree but couldn't figure it out directly. Very smart to pose it as a range sum question. Was missing your vid last week 😆
well explained, thanks man!
I was expecting your video Yesterday
How did you come up with this approach many people are using treemap/priority queue/min heap for it ,how to decide the good one? I personally loved this solution since it is straight forward! Thanks
Well I realized that I need to know the min value available and can get the rest from there so yeah either min heap or just use hashmap and array since my values never change. Heap better for when your values change instead of static.
Beautiful explanation! Thank you very much
killin it with the streak man..🍏🍏