- 115
- 112 970
C0de Sutra
India
Registrace 14. 08. 2014
The goal and aspiration of this channel is to build a community of high efficient Software Engineers. I share content with the intention of discussing with the community on better approaches to solve a problem and help software Engineers and aspiring software Engineers to get better at their professions.
Leetcode 3068 Find the Maximum Sum of Node Values
In this vedio I have discussed the solution to leetcode 3068. Find the Maximum Sum of Node Values
I have used greedy Algorithm to solve this problem.
Problem Link: leetcode.com/problems/find-the-maximum-sum-of-node-values/
Solution Link: leetcode.com/problems/find-the-maximum-sum-of-node-values/discuss/5176842/Beats-100-Video-Solution-or-Java-C%2B%2B-Python
Fresher's Community Link: chat.whatsapp.com/CsvgJRFNZTQAIcujub1gDe
Experienced Community Link: chat.whatsapp.com/IeeHQGlUPK25OFm7mIdv5G
I have used greedy Algorithm to solve this problem.
Problem Link: leetcode.com/problems/find-the-maximum-sum-of-node-values/
Solution Link: leetcode.com/problems/find-the-maximum-sum-of-node-values/discuss/5176842/Beats-100-Video-Solution-or-Java-C%2B%2B-Python
Fresher's Community Link: chat.whatsapp.com/CsvgJRFNZTQAIcujub1gDe
Experienced Community Link: chat.whatsapp.com/IeeHQGlUPK25OFm7mIdv5G
zhlédnutí: 463
Video
LeetCode 979 Distribute Coins in Binary Tree
zhlédnutí 476Před 2 měsíci
Solution to leetcode problem 979.Distribute Coins in Binary Tree I have used post Order traversal to solve this leetcode problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/distribute-coins-in-binary-tree/ Solution Link: leetcode.com/problems/distribute-coins-in-binary-tree/discuss/5172664/Beats-100-Video-Solution-with-Similar-Problems-or-J...
Leetcode 1325. Delete Leaves With a Given Value
zhlédnutí 62Před 2 měsíci
Leetcode 1325. Delete Leaves With a Given Value Given a binary tree root and an integer target, delete all the leaf nodes with value target. Post Order Traversal is used in the solution
Leetcode 1531 String Compression II
zhlédnutí 1,3KPřed 7 měsíci
Solution to leetcode problem 1531. String Compression II I have used Dynamic Programming DP to solve this problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/string-compression-ii/ Solution Link: leetcode.com/problems/string-compression-ii/discuss/4468981/Video-Solution-DP-or-Java-C++-Python
Leetcode 2050 Parallel Courses III
zhlédnutí 767Před 9 měsíci
Solution to leetcode problem 2050. Parallel Courses III I have used Topological Sort to solve this problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: //leetcode.com/problems/parallel-courses-iii/ Solution Link: leetcode.com/problems/parallel-courses-iii/discuss/4180629/Video-Solution-or-Java-C++-Python
Leetcode 1269 Number of Ways to Stay in the Same Place After Some Steps
zhlédnutí 652Před 9 měsíci
Solution to leetcode problem 1269. Number of Ways to Stay in the Same Place After Some Steps I have used Dynamic Programming (DP) to solve this problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps/ Solution Link:
Leetcode 2742 Painting the Walls
zhlédnutí 1,3KPřed 9 měsíci
Solution to leetcode problem 2742. Painting the Walls I have used Dynamic Programming (DP) to solve this problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/painting-the-walls/ Solution Link: leetcode.com/problems/painting-the-walls/discuss/4166315/Video-Solution-or-Dynamic-Programming
LeetCode 2251 Number of Flowers in Full Bloom
zhlédnutí 1,1KPřed 9 měsíci
Solution to leetcode problem 2251. Number of Flowers in Full Bloom I have used sorting and Binary Search to solve this problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/number-of-flowers-in-full-bloom/ Solution Link: leetcode.com/problems/number-of-flowers-in-full-bloom/discuss/4155615/Video-Solution-or-Sorting-and-Binary-Search
LeetCode 2009 Minimum Number of Operations to Make Array Continuous
zhlédnutí 1,4KPřed 9 měsíci
Solution to leetcode problem 2009. Minimum Number of Operations to Make Array Continuous. I have used sorting and Sliding window Technique to solve this problem. Telegram Links: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/minimum-number-of-operations-to-make-array-continuous/ Solution Link: leetcode.com/problems/minimum-number-of-operations-to-make-array-co...
Leetcode 1203 Sort Items by Groups Respecting Dependencies
zhlédnutí 3,4KPřed 11 měsíci
Telegram Link: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/sort-items-by-groups-respecting-dependencies/description/ Solution Link: leetcode.com/problems/sort-items-by-groups-respecting-dependencies/solutions/3934487/detailed-video-solution-java-c-python/ Sort Items by Groups Respecting Dependencies is leetcode 1489 and we are using Topological Sort to solv...
Leetcode 1489 Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree
zhlédnutí 1KPřed 11 měsíci
Telegram Link: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/ Solution Link: leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/discuss/3929349/Detailed-Video-+-Solution-or-Java-C++-Python Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree is lee...
Leetcode 542 01 Matrix
zhlédnutí 1,4KPřed 11 měsíci
Telegram Link: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/01-matrix/ Solution Link: leetcode.com/problems/01-matrix/discuss/3920311/Greedy-Beats-100-or-Java-C++-Python 01 Matrix is leetcode 542 and we are using greedy algorithm to solve this problem. The time and space complexity are O(N*M) and O(1).
Leetcode 2369 Check if There is a Valid Partition For The Array
zhlédnutí 815Před 11 měsíci
Workshop Link:jeevankumar.co.in/ Telegram Link: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array Solution Link: leetcode.com/problems/check-if-there-is-a-valid-partition-for-the-array/discuss/3901362/Easy-Explanation-+-Video-or-Java-C++-Python Check if There is a Valid Partition For The Array is leetcode 2369 and...
Leetcode 63 Unique Paths II
zhlédnutí 924Před 11 měsíci
Workshop Link:jeevankumar.co.in/ Telegram Link: t.me/ FieKB7Ds6j02Y2Y1 t.me/ JU-ZF-oDjX4xYjBl Problem Link: leetcode.com/problems/unique-paths-ii/ Solution Link: leetcode.com/problems/unique-paths-ii/discuss/3897008/Beats-100-+Video-or-Java-C++-Python Unique Paths II is leetcode 63 and we are using dynamic programming (dp) to solve this problem. The time and space complexity are O(n*m) and O(n*m).
Leetcode 2616 Minimize the Maximum Difference of Pairs
zhlédnutí 2KPřed 11 měsíci
Leetcode 2616 Minimize the Maximum Difference of Pairs
Leetcode 33 Search in Rotated Sorted Array
zhlédnutí 710Před 11 měsíci
Leetcode 33 Search in Rotated Sorted Array
Leetcode 95 Unique Binary Search Trees II
zhlédnutí 2,8KPřed 11 měsíci
Leetcode 95 Unique Binary Search Trees II
Leetcode 17 Letter Combinations of a Phone Number
zhlédnutí 838Před 11 měsíci
Leetcode 17 Letter Combinations of a Phone Number
Leetcode 712 Minimum ASCII Delete Sum for Two Strings
zhlédnutí 1,4KPřed 11 měsíci
Leetcode 712 Minimum ASCII Delete Sum for Two Strings
Leetcode 2141 Maximum Running Time of N Computers
zhlédnutí 1,6KPřed rokem
Leetcode 2141 Maximum Running Time of N Computers
LeetCode 1870 Minimum Speed to Arrive on Time
zhlédnutí 1,5KPřed rokem
LeetCode 1870 Minimum Speed to Arrive on Time
Leetcode 852 Peak Index in a Mountain Array
zhlédnutí 848Před rokem
Leetcode 852 Peak Index in a Mountain Array
LeetCode 688 Knight Probability in Chessboard
zhlédnutí 846Před rokem
LeetCode 688 Knight Probability in Chessboard
LeetCode 673 Number of Longest Increasing Subsequence
zhlédnutí 1,3KPřed rokem
LeetCode 673 Number of Longest Increasing Subsequence
LeetCode 435 Non-overlapping Intervals
zhlédnutí 1,1KPřed rokem
LeetCode 435 Non-overlapping Intervals
4.22 where did 7 came from. i didnt understood
Thanks
Welcome! I am glad you liked it.
Thanks
you are the best
Thank you!
why are we initialising 0 with count 1 , I couldn't understand that point
okay got it this 0 is for say like if the sub array is a total array then we should have a value in hash map zero
thanks
You explained it very nicely. Looking forward to more videos
but what if the [0,0] is not 0?
how to think of this logic sir ?
Keep it going ! :D
you explained the steps but you didn't explain how and why it works
Can you please share the time and space complexities as well
what's the app you using to note?
Fresher's Community Link: chat.whatsapp.com/CsvgJRFNZTQAIcujub1gDe Experienced Community Link: chat.whatsapp.com/IeeHQGlUPK25OFm7mIdv5G
Keep it up man !
Thank you!
Hey bro, will you be uploading answer of daily challenges everyday? and good approach!
Yes Sharan I will be uploading solution for the medium and Hard level problems. Thank you!
Telegram Links: t.me/+FieKB7Ds6j02Y2Y1 t.me/+JU-ZF-oDjX4xYjBl
Similar Problems: leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree/ leetcode.com/problems/binary-tree-cameras/
Please improve your pronunciation. I can’t listen you.
why didnt you finish the seaies.. this is exactly what I was looking for
Good explanation
Like the explaination but solution is far from ideal and will timeout if run with higher inputs
Nice explanation
best explaination for the java submission
00:02 Problem requires step-by-step approach 02:20 Finding the shortest path to collect all keys 04:43 Path to obtaining keys to unlock cells. 07:03 Using binary representation to store key configurations efficiently 09:15 Using numbers to represent key configurations simplifies identification 11:37 Algorithm for finding shortest path to get all keys. 13:49 Finding the shortest path to get all keys with specific conditions. 16:03 Traversal and key management in pathfinding algorithm. 18:00 Iterating over elements in the queue and updating steps
code for pair ?
brute force solution is incorrect. It will fail on the test case [1,100,5]. Explanation: One possible case is when player 1 picks 5. Player 2 picks 1. Player 1 picks 100. This situation will arise because you are considering all possible cases and this case will also fall under it. Your solution will return true but expected answer is false
Thank you for your explanation! It's better than on many other channels!
in 10:19 why to take a2 for a7 and for a10 to a3 I did'nt understand this
It's the length of the new String i.e a7 has a length of 2 and a10 has a length of 3
This is my java solution: Logically It makes sense to me but I am having trouble with the testcases, any pointers will help: class Solution { public int getLengthOfOptimalCompression(String s, int k) { int[][] x = new int[s.length() + 1][k + 1]; for(int[] j : x){ Arrays.fill(j, -1); } return find(s, k, 0, x, Character.MIN_VALUE, 0); } int find(String s, int k, int index, int[][] x, char cur, int charcount){ if(k == 0 || index >= s.length()){ return Calculate_len(s, index); } if(x[index][k] != -1){ return x[index][k]; } int count = 0; if(cur != s.charAt(index)){ String num = String.valueOf(charcount); int val = 0; if(num.equals("1")){ val = 1; } else if(num.equals("0")){ val = 0; } else{ val = num.length() + 1; } // System.out.println(num + " " + val); count = Math.min(find(s, k, index + 1, x, s.charAt(index),1) + val, find(s, k - 1, index + 1, x, cur, charcount)); } else{ count = Math.min(find(s, k, index + 1, x, s.charAt(index),charcount + 1), find(s, k - 1, index + 1, x, cur, charcount)); } x[index][k] = count; // System.out.println(x[index][k] + " " + index + " " + k); return x[index][k]; } int Calculate_len(String s, int index){ if(index >= s.length()){ return 0; } String ns = s.substring(index); int i = 0; int fin_count = 0; while(i < ns.length()){ int count = 1; while(i < ns.length() - 1 && ns.charAt(i) == ns.charAt(i + 1)){ count++; i++; } if(count == 1){ fin_count++; } else{ String num = String.valueOf(count); fin_count += (num.length() + 1); } i++; } return fin_count; } }
Check out our community of 400+ people: t.me/+FieKB7Ds6j02Y2Y1
class Solution { public: int dp[102][102]; int find(int n){ if(n==1) return 1; if(n>1 and n<10) return 2; if(n>=10 and n<100) return 3; return 4; } int solve(string &s,int k,int idx){ if(k<0) return s.size(); if(idx>=s.size() || (s.size()-idx)<=k) return 0; if(dp[idx][k]!=-1) return dp[idx][k]; int ans=s.size(); ans=solve(s,k-1,idx+1); int cons=0,cnt=0,j; for( j=idx;j<s.size() && cnt<=k;j++){ if(s[j]==s[idx]) cons++; else{ ans=min(ans,find(cons)+solve(s,k-cnt,j)); cnt++; } } if(cnt<=k) ans=min(ans,find(cons)+solve(s,k-cnt,j)); return dp[idx][k]=ans; } int getLengthOfOptimalCompression(string s, int k) { memset(dp,-1,size(dp)); return solve(s,k,0); } }; what is the error in my code
Thanks
Welcome!!
Wow very simply and beautifully explained!
Thanks bro
Thank you, well explained.
Nice thumbnail ❤
Very energetic and enthusiastic way of explaining the solution. Thanks much.
I am glad you liked it ❤️
Simplified and clear explanation.
nice explanatory video
Thank you
Nice
Thank you!!
Bro, this was dope. Thanks a lot.
Thank you!!
Amazing Explanation, brooo!!! 💯💯
Thank you Bruh!!
Nice presentation
Thank you!!
Telegram Links: t.me/+FieKB7Ds6j02Y2Y1 t.me/+JU-ZF-oDjX4xYjBl
The first approach is O(mlogm) m = no of batteries and the binary search approach is O(mlogk). It's given that k >> m. It seems that the frist one is better. Why use binary search?
you are helping a lot but sometime your voice buffer so much and sound like not a ear friendly so plz improve your voice quality just a suggestion anyways you are doing great thanks for sharing :)
Thank you for your feedback!! Will surely correct
I wasnt able to think of 1D dp solution so I wrote 2D dp code and converted the dp array to an unordered map and combined the 2 states to a single string in the map , and got AC. will this be a valid solution in the interview ??
Yes this will be valid!! However if you are in a interview the interviewer will guide or direct you towards a 2d array for mem. Once you have come up with a solution that gets accepted, just think if you can make it still better. I am pretty sure if you came up with hashmap, coming up with 2d array will be very easy for you.
@@c0de_sutra initially I came up with 2D dp solution only but I got runtime as constrains for n was 10^6 and steps were 500 so my code was making a 2D array of about 5 * 10^8 size which is prohibited in c++ even if it is global array , I believe the limit is 10^7 for global arrays , hence I tried to reduce a state using map. Can this problem be solved only using 1 state i.e. steps parameter ? . I read the hint2 on leetcode for this question which said "Notice that the computational complexity does not depend of "arrlen".
can we use recursive DP with Memoization (using a HashMap for storing values) for this problem?
Yes, you can try that. But since all states will be visited, the hashmap will increase to same size.
Sir, I thought about this problem like this: If I add up the totalTime and start with that: f(n,totalTime, T). If I went for not_take, totalTime will decrease by one and if I went for take, totalTime will increase by time[i]. If totalTime is greater than the start(T) then return 0 else return 1e9. Hence the dp will be [n+1][2*totalTime+1]. But it gives Memory Limit Exceeded. If I use your way which is [n][n+1], it will work. Mr. how should I know this is the correct way to solve starting from recursion? Thank you for your amazing videos bhaiya!!!