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Күн бұрын
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Күн бұрын
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Күн бұрын
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Күн бұрын
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Күн бұрын
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Күн бұрын
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Күн бұрын
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Күн бұрын
How to solve if the values are in negative numbers?
@jishnubrataghosh49572 күн бұрын
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] } }
@dipangshuroy62302 күн бұрын
Watching your video after years, welcome back man 🔥
@anushakandagal17272 күн бұрын
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 😁
@updates84552 күн бұрын
Brother! I am solving problems without even looking at your solutions. Thanks
@motionkings2 күн бұрын
Bhai tune hi bola ke sabse pehle recursive solution Karna hota hai but ab tummy starting se tabulation Karne lag gye
@jayasuryagunasekharan4233 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan4233 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan4233 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan4233 күн бұрын
bring back Aditya Verma
@jayasuryagunasekharan4233 күн бұрын
bring back Aditya Verma
@cleverpheonix40783 күн бұрын
what if array is rather non-increasing instead of strictly decreasing and vice-versa
@_CodeLifeChronicles_3 күн бұрын
completed the whole playlist hurray
@NikhilRaj-rr2fl3 күн бұрын
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.
@chinmay44523 күн бұрын
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-ig2jq3 күн бұрын
What will be the minimum distance when the weight of the edge is given... will BFS fail there?
@TheAnmolPunetha3 күн бұрын
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!
@Pihu42103 күн бұрын
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) .
@pranavJha933 күн бұрын
dhanyavad bhai
@pranavJha933 күн бұрын
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; } };
@sbndBhanu5463 күн бұрын
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++; } }
@yaswanthg35363 күн бұрын
BC Matlab woh nahi Hai, ye base Conditon hai😂
@ehtashammazhar35183 күн бұрын
does it work for this input : 7 1 1 7 5 expected output : 4
@programmingwallah29053 күн бұрын
Best bhaiya❤
@aishwarya_v_r4 күн бұрын
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_r4 күн бұрын
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?
@dakshkriplani11424 күн бұрын
we need aditya back
@rudrakhare11584 күн бұрын
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
@CodersCorner21214 күн бұрын
Broo..you r amazingg
@vineetjadhav17854 күн бұрын
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 ❤
@shubhamtiwari77044 күн бұрын
please increase the frequency, please
@pratikkumar50864 күн бұрын
Can also be done by finding the maximum value close to sum/2
@mohitpatel90254 күн бұрын
Aditya bhaiya aap aiye plz bahoot jarurat he apka
@GautamPanday-z9q4 күн бұрын
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_army4 күн бұрын
Solved it before watching the video using basic idea of four steps, you are so great and so much love this playlist❤
@sagarsunar65015 күн бұрын
mazaaa aah gyaaa!! 🚬
@kitkat5845 күн бұрын
I almost solved it. It fits with Binary Search + Recursion (for considering the two possibilities)
@AshutoshDahal-lf7ul5 күн бұрын
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-rr2fl5 күн бұрын
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); } }
@vkhs5625 күн бұрын
Recursion literally made easy!!
@sushmitagoswami20335 күн бұрын
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.
@shivaji0115 күн бұрын
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.
@sambhavjain36535 күн бұрын
thats an amazing explanation but how would we deal when array has negative integers? can you make an explanation of that?