13 Cycle Detection | Graph
22:17
14 күн бұрын
12 Reorder routes | Graph
31:09
14 күн бұрын
11 Steps by Knight | Graph | Code
32:21
10 Steps by Knight | Graph
38:10
21 күн бұрын
9 Find if path exists | Code | Graph
19:23
8 Find if path exists | Graph
28:18
7 Depth-First Search | Graph
34:31
6 Breadth First Search | Graph
32:18
5 Graph Traversal | Graph
22:50
3 Graph Implementations | Graph
28:35
2 Types of graphs | Graph
30:54
21 Sudoku Solver | Part 2
28:16
2 ай бұрын
20 Sudoku Solver | Part 1
31:42
2 ай бұрын
19 N Queens | Part 2
27:17
2 ай бұрын
18 N Queens | Part 1
44:04
2 ай бұрын
16 Word Break | Part 2
20:59
2 ай бұрын
15 Word Break | Part 1
33:56
2 ай бұрын
13 Rat in a Maze Problem Code
17:29
12 Rat in a Maze Problem
25:29
8 ай бұрын
9 Largest number in K swaps
36:47
9 ай бұрын
Пікірлер
@sheshanksrivastava403
@sheshanksrivastava403 23 сағат бұрын
bhai ji raat je 11:44 ho rahe hai aur mai abhi tak issi video par hu, 4 din ho gaye. Any tips to improve sitting time (long practice time).
@KishanGupta-qe2yk
@KishanGupta-qe2yk Күн бұрын
Plz plz tell me Isee padhne ke liye hame java language aana chahiye ya c++ kisme padhaye hai ye dsa series plz tell
@KishanGupta-qe2yk
@KishanGupta-qe2yk Күн бұрын
Plz plz tell me Isee padhne ke liye hame java language aana chahiye ya c++ kisme padhaye hai ye dsa series plz tell
@KishanGupta-qe2yk
@KishanGupta-qe2yk Күн бұрын
Plz plz tell me Isee padhne ke liye hame java language aana chahiye ya c++ kisme padhaye hai ye dsa series plz tell
@KishanGupta-qe2yk
@KishanGupta-qe2yk Күн бұрын
Plz plz tell me Isee padhne ke liye hame java language aana chahiye ya c++ kisme padhaye hai ye dsa series plz tell
@Ekam-zs1vh
@Ekam-zs1vh Күн бұрын
Rather than erasing we can move the index to avoid modifying the original string and in base case index will be equal to length of string
@sarcastic_army
@sarcastic_army Күн бұрын
for those who are getting TLE on gfg, try using binary search traversal instead of for loop traversal for every floor. For better understanding----> static int eggDrop(int n, int k) { // Your code here int[][] dp = new int[n+1][k+1]; for(int i=0; i<=k; i++){ dp[1][i] = i; } for(int i=0; i<=n; i++){ dp[i][0] = 0; dp[i][1] = 1; } for(int e=2; e<=n; e++){ for(int f=2; f<=k; f++){ int low=1, high=f; int min = Integer.MAX_VALUE; while(low<=high){ int mid = (int)(low+high)/2; int yesbreak = dp[e-1][mid-1]; int nobreak = dp[e][f-mid]; int worst = 1 + Math.max(nobreak, yesbreak); min = Math.min(min , worst); if(yesbreak > nobreak) high = mid-1; else low = mid+1; } dp[e][f] = min; } } return dp[n][k]; }
@lakshyaagarwal4212
@lakshyaagarwal4212 Күн бұрын
in this question we can use a different approach .everytime we add a new character in the string if the count of that character is greater than 1 then we can shift the window. if character count is 1 then we simply change the length of the max substring.
@chaitrabhat8199
@chaitrabhat8199 Күн бұрын
How to solve if the values are in negative numbers?
@jishnubrataghosh4957
@jishnubrataghosh4957 2 күн бұрын
java code - import java.util.ArrayList; import java.util.Stack; public class NearestLargerToLeft { public static ArrayList<Integer> nearestLargerToLeft(int[] a) { Stack<Integer> stack = new Stack<>(); ArrayList<Integer> res = new ArrayList<>(); for (int i = 0; i < a.length; i++) { while (!stack.isEmpty() && stack.peek() <= a[i]) { stack.pop(); } if (stack.isEmpty()) { res.add(-1); } else { res.add(stack.peek()); } stack.push(a[i]); } return res; } public static void main(String[] args) { int[] a = {2, 3, 6, 4, 3, 3, 6, 7}; ArrayList<Integer> result = nearestLargerToLeft(a); System.out.println(result); // Output: [-1, -1, -1, 6, 4, 4, -1, -1] } }
@dipangshuroy6230
@dipangshuroy6230 2 күн бұрын
Watching your video after years, welcome back man 🔥
@anushakandagal1727
@anushakandagal1727 2 күн бұрын
Much simpler solution without using any graph traversals!! 1) Use a HashSet to track nodes that can reach 0 2) flip the rest of the connections and increment count 3) Update the set ( step 1) 4) Repeat untill the set has all nodes. class Solution { public int minReorder(int n, int[][] connections) { Set<Integer> bridges = new HashSet<>(); bridges.add(0); n--; int reorder = 0; while(bridges.size() <= n){ for(int i = 0; i < connections.length; i++){ if(bridges.contains(connections[i][1])){ bridges.add(connections[i][0]); } else if(bridges.contains(connections[i][0])){ int temp = connections[i][0]; connections[i][0] = connections[i][1]; connections[i][1] = temp; reorder++; bridges.add(connections[i][0]); } } } return reorder; } } But only solves 76/77 test cases , the last test case will fail at TLE 😁
@updates8455
@updates8455 2 күн бұрын
Brother! I am solving problems without even looking at your solutions. Thanks
@motionkings
@motionkings 2 күн бұрын
Bhai tune hi bola ke sabse pehle recursive solution Karna hota hai but ab tummy starting se tabulation Karne lag gye
@jayasuryagunasekharan423
@jayasuryagunasekharan423 3 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan423
@jayasuryagunasekharan423 3 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan423
@jayasuryagunasekharan423 3 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan423
@jayasuryagunasekharan423 3 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan423
@jayasuryagunasekharan423 3 күн бұрын
bring back Aditya Verma
@cleverpheonix4078
@cleverpheonix4078 3 күн бұрын
what if array is rather non-increasing instead of strictly decreasing and vice-versa
@_CodeLifeChronicles_
@_CodeLifeChronicles_ 3 күн бұрын
completed the whole playlist hurray
@NikhilRaj-rr2fl
@NikhilRaj-rr2fl 3 күн бұрын
Making this video while dealing with the flu and choosing not to rest shows your dedication to completing this playlist and your commitment as a teacher.
@chinmay4452
@chinmay4452 3 күн бұрын
04:51 But the result of k sorted array is not necessarily the simple sorted array. For ex: For Input: 8 3 4 9 2 5 4 8 9 2 Expected Output: 3 4 2 5 4 8 8 9 9 Here expected output is not overall sorted array.
@AnkurTripathi-ig2jq
@AnkurTripathi-ig2jq 3 күн бұрын
What will be the minimum distance when the weight of the edge is given... will BFS fail there?
@TheAnmolPunetha
@TheAnmolPunetha 3 күн бұрын
Because then the distance would be based upon the weights. Reason why BfS will fail is because bfs is just a traversal and it won’t be able to take min weights into consideration. (Because you don’t traverse based upon the weights). For that we will use DIJKSTRA ALGO, the OG!
@Pihu4210
@Pihu4210 3 күн бұрын
Sir can you explain how the logic would change when there are negative numbers especially when the total sum of elements is equal to 0(zero) .
@pranavJha93
@pranavJha93 3 күн бұрын
dhanyavad bhai
@pranavJha93
@pranavJha93 3 күн бұрын
class Solution { public: // Function to return max value that can be put in knapsack of capacity W. int solveMemo(int W,int n,vector<int>&wt,vector<int>& val,vector<vector<int>>&dp){ if(W == 0 || n == 0){ return 0; } if(dp[n][W] != -1) return dp[n][W]; if(wt[n-1] <= W){ int include = val[n-1] + solveMemo(W-wt[n-1],n-1,wt,val,dp); int exclude = solveMemo(W,n-1,wt,val,dp); dp[n][W] = max(include,exclude); return dp[n][W]; } else if(wt[n-1] > W){ dp[n][W] = solveMemo(W,n-1,wt,val,dp); return dp[n][W]; } } int knapSack(int W, vector<int>& wt, vector<int>& val) { // Your code here int n = wt.size(); vector<vector<int>>dp(n+1,vector<int>(W+1,-1)); int ans = solveMemo(W,n,wt,val,dp); return ans; } };
@sbndBhanu546
@sbndBhanu546 3 күн бұрын
instead of using queue first we traverse array and store negative number index in array and then appy sliding window instead of removing elements we move an index on that array Like the below code 👇👇 static void firstNegative(int[] nums, int k){ int len = nums.length; int i=0, j=0, t=0, q=0; int[] negarr = new int[len]; for (int l = 0; l < len; l++) { negarr[l] = -1; } while(j<len){ if(nums[j]<0){ negarr[t] = j; t++; } if(j-i+1 == k){ if(negarr[q]>-1 && negarr[q]>=i){ System.out.print(nums[negarr[q]] + " "); } else if(negarr[q]>-1) { q++; System.out.print(nums[negarr[q]] + " "); } else{ System.out.print(0 + " "); } i++; } j++; } }
@yaswanthg3536
@yaswanthg3536 3 күн бұрын
BC Matlab woh nahi Hai, ye base Conditon hai😂
@ehtashammazhar3518
@ehtashammazhar3518 3 күн бұрын
does it work for this input : 7 1 1 7 5 expected output : 4
@programmingwallah2905
@programmingwallah2905 3 күн бұрын
Best bhaiya❤
@aishwarya_v_r
@aishwarya_v_r 4 күн бұрын
I saw that there is a 1-D solution as well for this question. How do you get to that from the 2D or the memoized solution?
@aishwarya_v_r
@aishwarya_v_r 4 күн бұрын
I saw that there is a 1-D solution as well for this question. How do you get to that from the 2D or the memoized solution?
@dakshkriplani1142
@dakshkriplani1142 4 күн бұрын
we need aditya back
@rudrakhare1158
@rudrakhare1158 4 күн бұрын
Can Be Done Using Two Pointers as shown in video and Using Deque As Well. Two Pointers- def printFirstNegativeInteger(A, N, K): l = 0 # Left pointer of the window r = 0 # Right pointer of the window temp = [] # To store negative numbers in the current window final_ans = [] # To store the result while r < N: if A[r] < 0: # If the current element is negative, add it to temp temp.append(A[r]) # If the window size is less than K, just move the right pointer if r - l + 1 < K: r += 1 # When the window size is exactly K elif r - l + 1 == K: if len(temp) == 0: final_ans.append(0) # If no negative number in the window, append 0 else: final_ans.append(temp[0]) # Append the first negative number in the window # Slide the window if A[l] == temp[0]: # If the element sliding out is negative, remove it from temp temp.pop(0) l += 1 # Move the left pointer r += 1 # Move the right pointer return final_ans Deque- from collections import deque def firstNegativeInWindow(nums, k): result = [] dq = deque() # To store indices of negative numbers n = len(nums) for i in range(n): # Add current element index if it's negative if nums[i] < 0: dq.append(i) # Remove elements that are out of the current window if dq and dq[0] < i - k + 1: dq.popleft() # Once we have at least one window of size k if i >= k - 1: # The first element in deque is the first negative integer if dq: result.append(nums[dq[0]]) else: result.append(0) return result
@CodersCorner2121
@CodersCorner2121 4 күн бұрын
Broo..you r amazingg
@vineetjadhav1785
@vineetjadhav1785 4 күн бұрын
I have completed 50% of the playlist and I must say earlier I was scared about DP, but its not the case now, I have been able to draw intuition of many problems on my own and can code 90% of the solution. Thanks Aditya Bhai for the teaching ❤
@shubhamtiwari7704
@shubhamtiwari7704 4 күн бұрын
please increase the frequency, please
@pratikkumar5086
@pratikkumar5086 4 күн бұрын
Can also be done by finding the maximum value close to sum/2
@mohitpatel9025
@mohitpatel9025 4 күн бұрын
Aditya bhaiya aap aiye plz bahoot jarurat he apka
@GautamPanday-z9q
@GautamPanday-z9q 4 күн бұрын
The question is literally same as leetcode 904 - Fruit into Baskets...hope this comment helps👍 And ya, thank you so much Aditya bhaiya for improving my coding skills , if your channel was not there , I would have been dead🙏
@sarcastic_army
@sarcastic_army 4 күн бұрын
Solved it before watching the video using basic idea of four steps, you are so great and so much love this playlist❤
@sagarsunar6501
@sagarsunar6501 5 күн бұрын
mazaaa aah gyaaa!! 🚬
@kitkat584
@kitkat584 5 күн бұрын
I almost solved it. It fits with Binary Search + Recursion (for considering the two possibilities)
@AshutoshDahal-lf7ul
@AshutoshDahal-lf7ul 5 күн бұрын
It did it a litttle bit differently. And It WORKS!! Used your technique again!!!💕 char L = '(', R = ')'; void parenthesis(string output, int left, int right) { if (left == 0 && right == 0) { cout << output << endl; return; } if (left == right) { output += L; left--; } if (left == 0) { parenthesis(output + R, left, right - 1); return; } parenthesis(output + L, left - 1, right); parenthesis(output + R, left, right - 1); }
@NikhilRaj-rr2fl
@NikhilRaj-rr2fl 5 күн бұрын
This solution will work only when you have the largest value of node is equal to or less than the size of the input vector<vector>. It will not work for this input : {11, 5}, {6, 3}, {3, 4}, {4, 2}, {1, 3} here is the code which works for all the scenarios : import java.util.*; public class GraphAdjMatrix { // Function to print the adjacency matrix graph public static void printGraph(int[][] adjacencyMatrix) { for (int i = 1; i < adjacencyMatrix.length; i++) { System.out.print("Node: " + i + ", Neighbors: "); for (int j = 1; j < adjacencyMatrix.length; j++) { if (adjacencyMatrix[i][j] == 1) { System.out.print(j + " "); } } System.out.println(); } } public static void main(String[] args) { // Define the edge list int[][] edgeList = { {11, 5}, {6, 3}, {3, 4}, {4, 2}, {1, 3} }; // Find the maximum node value to size the adjacency matrix correctly int maxNode = 0; for (int[] edge : edgeList) { maxNode = Math.max(maxNode, Math.max(edge[0], edge[1])); } int[][] adjacencyMatrix = new int[maxNode + 1][maxNode + 1]; // Create matrix of appropriate size // Fill the adjacency matrix from the edge list for (int i = 0; i < edgeList.length; i++) { int a = edgeList[i][0]; int b = edgeList[i][1]; adjacencyMatrix[a][b] = 1; // Undirected graph, so add edges both ways adjacencyMatrix[b][a] = 1; } // Print the graph printGraph(adjacencyMatrix); } }
@vkhs562
@vkhs562 5 күн бұрын
Recursion literally made easy!!
@sushmitagoswami2033
@sushmitagoswami2033 5 күн бұрын
KZbin - "These are the videos you should recommend when someone searches for DP", being said recommendation algorithm most probably not robust. Along with likes and views, you should also consider quality of comments.
@shivaji011
@shivaji011 5 күн бұрын
Amazing playlist. One request, if you can tell us where you learn this stuff it will be great help. As I don't like getting fish in hand. I want to learn fishing.
@sambhavjain3653
@sambhavjain3653 5 күн бұрын
thats an amazing explanation but how would we deal when array has negative integers? can you make an explanation of that?