Тёмный
AlgorithmHQ
AlgorithmHQ
AlgorithmHQ
Подписаться
For all the problem solvers and maybe in coming days for technology enthusiasts, this channel serves as a hub for finding solutions to tech problems and expanding general knowledge about technology. What began as a hobby has evolved into a dream of making a significant impact, with the goal of becoming a valuable resource for technology enthusiasts everywhere. Our mission is to provide helpful, insightful content that empowers and inspires the tech community.
Комментарии
@ashuyadav2844
@ashuyadav2844 7 часов назад
hello Aditi, here is c++ code with 2D dp note: s.substr(start,length): this function take length instead of end in c++, class Solution { public: bool solve(int start ,int end,string &s,set<string> &wD,vector<vector<int>> &dp){ if(dp[start][end]!=-1){ return dp[start][end]==1 ?true:false; } if(end==s.length()-1){ if(wD.contains(s.substr(start,end - start + 1))){ dp[start][end] = 1; return true; } return false; } if(wD.contains(s.substr(start,end - start + 1))){ if(solve(end+1,end+1,s,wD,dp)) { dp[start][end]=1; return true; } } bool ans=solve(start,end+1,s,wD,dp); dp[start][end]= ans ? 1:0; return ans; } bool wordBreak(string s, vector<string>& wordDict) { set<string>wd(wordDict.begin(), wordDict.end()); vector<vector<int>> dp(s.length(), vector<int>(s.length(), -1)); return solve(0,0,s,wd,dp); } };
@harshmalakar
@harshmalakar 12 часов назад
Hare krishn 🙏
@kaviyans476
@kaviyans476 13 часов назад
testcase 72 did not pass . but also thank you for your idea
@pranawkaushal2932
@pranawkaushal2932 4 дня назад
public String convert(String s, int numRows) { if (numRows == 1) return s; // Edge case for a single row StringBuilder[] rows = new StringBuilder[numRows]; for (int i = 0; i < numRows; i++) { rows[i] = new StringBuilder(); } int i = 0; while (i < s.length()) { for (int index = 0; index < numRows && i < s.length(); index++) { rows[index].append(s.charAt(i++)); } for (int index = numRows - 2; index > 0 && i < s.length(); index--) { rows[index].append(s.charAt(i++)); } } StringBuilder sb = new StringBuilder(); for (StringBuilder str : rows) { sb.append(str.toString()); } return sb.toString(); } We can use StringBuilder instead of String for memory optimization
@algorithmsbyaditi
@algorithmsbyaditi 4 дня назад
Great work !
@user-oi5ls4rs5g
@user-oi5ls4rs5g 4 дня назад
Please upload more video
@kingsenior516
@kingsenior516 4 дня назад
Very well explained and also the code was pretty clean, thank you
@algorithmsbyaditi
@algorithmsbyaditi 4 дня назад
Glad it helped!
@GauravSingh-xs6qn
@GauravSingh-xs6qn 6 дней назад
Radhe radhe 😊
@user-of3ss6hb2l
@user-of3ss6hb2l 7 дней назад
Good explanation ! ✨
@princesingh289
@princesingh289 8 дней назад
I think this can be solved more easily using DFS void helper(vector<vector<char>>& board,int i,int j,int n,int m, int t, string word,bool &flag) { if(t==(word.size())) { flag=true; return; } if(i<0 || j<0 || i>n-1 || j>m-1 || board[i][j]=='0') return; if(board[i][j]==word[t]) { board[i][j]='0'; helper(board,i-1,j,n,m,t+1,word,flag); helper(board,i,j-1,n,m,t+1,word,flag); helper(board,i+1,j,n,m,t+1,word,flag); helper(board,i,j+1,n,m,t+1,word,flag); board[i][j]=word[t]; } return; } bool exist(vector<vector<char>>& board, string word) { int n=board.size(); int m=board[0].size(); bool flag=false; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { helper(board,i,j,n,m,0,word,flag); } } return(flag); }
@navinsahu2101
@navinsahu2101 8 дней назад
thank you ma'am after a very long time , welcome back
@ITACH1688
@ITACH1688 8 дней назад
Thanks ma'am, also welcome back
@robinut
@robinut 8 дней назад
finally video after 2 weeks
@crystalgaming4050
@crystalgaming4050 8 дней назад
Please make a video on Rerooting DP Please solve and explain "Sum of distances in a tree" using rerooting dp
@algorithmsbyaditi
@algorithmsbyaditi 8 дней назад
Will have a look soon ! Thanks.
@sumitdhakad8332
@sumitdhakad8332 9 дней назад
Ram Ram Bhaiyon
@raaoohin863
@raaoohin863 11 дней назад
is this code efficient since we are using two maps and two for loops?
@feelyourbeat7820
@feelyourbeat7820 13 дней назад
HQ ki full form kya hai?
@Aladdin-y2q
@Aladdin-y2q 14 дней назад
can you explain this video in English, pls?
@arnabsarkar5245
@arnabsarkar5245 17 дней назад
Hello didi, i was trying this question. My code is slightly different from you. class Solution { List<List<Integer>> ans = new ArrayList<>(); List<Integer> res = new ArrayList<>(); public List<List<Integer>> combinationSum3(int k, int n) { // helper(1, k, n); helper2(1, k, n, 0); return ans; } public void helper2(int i, int size, int target, int sum) { if (i > 9) { return; } if (sum == target && res.size() == size) { ans.add(new ArrayList<>(res)); return; } sum += i; res.add(i); helper2(i + 1, size, target, sum); sum -= i; res.remove(res.size() - 1); helper2(i + 1, size, target, sum); } } Can you please tell my why it is failing for the case (9, 45)
@shikherdwivedi4559
@shikherdwivedi4559 17 дней назад
Amazing Explanation, keep doing the same work!
@algorithmsbyaditi
@algorithmsbyaditi 17 дней назад
Thank you
@user-if9hs7dl5v
@user-if9hs7dl5v 18 дней назад
Hare krsna 🙏
@saurabh0065
@saurabh0065 19 дней назад
you are not recursion
@animeshchourasia9374
@animeshchourasia9374 20 дней назад
very good explanation
@algorithmsbyaditi
@algorithmsbyaditi 19 дней назад
Thank you
@suyashmehare8034
@suyashmehare8034 20 дней назад
Thank you mam, this video was very helpful in my case.. i had come up with nearly same intuition but failed on test case : *( . I never think before that stack can also be useful this way. This is really genuine and creative way to solve... Thank you very much mam ❤
@algorithmsbyaditi
@algorithmsbyaditi 20 дней назад
Glad it was helpful !
@ritikshandilya7075
@ritikshandilya7075 21 день назад
I lost consistency last month and really happy to see more content for lot of questions from you . Thanks for great solution its really helpful
@algorithmsbyaditi
@algorithmsbyaditi 20 дней назад
Thank youu ! Keep going ✨
@RajChauhan-iu3dc
@RajChauhan-iu3dc 21 день назад
good work sister
@sanasainath7758
@sanasainath7758 22 дня назад
explain in english please
@darshandani1
@darshandani1 22 дня назад
Perhaps the most straightforward and easy to understand solution on RU-vid. Thanks for this ! 1
@algorithmsbyaditi
@algorithmsbyaditi 22 дня назад
Glad it was helpful !
@lazy_bug4246
@lazy_bug4246 22 дня назад
Thanks a lot. I tried watching NeetCode's video solution before this, but your explanation stuck with me.
@algorithmsbyaditi
@algorithmsbyaditi 22 дня назад
Glad it was helpful !
@lazy_bug4246
@lazy_bug4246 22 дня назад
@@algorithmsbyaditi please make a series on graphs ?
@algorithmsbyaditi
@algorithmsbyaditi 22 дня назад
Will try soon !
@crekso398
@crekso398 22 дня назад
thank you so muchh for such clear explaination.............. jai shree krishna!!!!
@algorithmsbyaditi
@algorithmsbyaditi 22 дня назад
Glad it was helpful !
@gunaranjanrajkumar2454
@gunaranjanrajkumar2454 22 дня назад
mam explain in english
@adarshjain3058
@adarshjain3058 22 дня назад
#include <vector> #include <algorithm> #include <climits> using namespace std; class Solution { public: int solve(vector<vector<int>>& books, int shelfWidth, int i, int currWidth, int currHeight, vector<vector<int>>& dp) { if (i >= books.size()) { return currHeight; } if (dp[i][currWidth] != -1) { return dp[i][currWidth]; } int minHeight = INT_MAX; // Option 1: Place the current book on the same shelf if it fits if (currWidth + books[i][0] <= shelfWidth) { minHeight = solve(books, shelfWidth, i + 1, currWidth + books[i][0], max(currHeight, books[i][1]), dp); } // Option 2: Place the current book on a new shelf minHeight = min(minHeight, currHeight + solve(books, shelfWidth, i + 1, books[i][0], books[i][1], dp)); return dp[i][currWidth] = minHeight; } public: int minHeightShelves(vector<vector<int>>& books, int shelfWidth) { int n = books.size(); vector<vector<int>> dp(n + 1, vector<int>(shelfWidth + 1, -1)); return solve(books, shelfWidth, 0, 0, 0, dp); } }; shame shame but diffelent
@vinayakporwal9885
@vinayakporwal9885 22 дня назад
Some tips as a audience perspective - 1. Try to stick to one thumbnail for a category videos for example - daily problem solving series must have a same thumbnail design that will help your previous audience to catch that thumbnail quickly and it will look well maintained. 2. Enhance your thumbnail quality using any image upscaler. All the best
@algorithmsbyaditi
@algorithmsbyaditi 22 дня назад
Thank you for the suggestions, will definitely try to incorporate.
@vinayakporwal9885
@vinayakporwal9885 22 дня назад
Keep going 🚀
@algorithmsbyaditi
@algorithmsbyaditi 7 дней назад
Always
@adarshjain3058
@adarshjain3058 22 дня назад
attendance++ captain;
@crekso398
@crekso398 23 дня назад
thank you so much.. i was trying it by stack but it was time taking... thank you so much for sharing this... i got to learn one more thing today.
@algorithmsbyaditi
@algorithmsbyaditi 23 дня назад
Glad it was helpful !
@ShreyasNarule
@ShreyasNarule 23 дня назад
Try to post the solution for GFG POTD
@algorithmsbyaditi
@algorithmsbyaditi 23 дня назад
Will try soon !
@rahulgrover3104
@rahulgrover3104 23 дня назад
Nice explanation! ..But we don't need else condition where u r putting b as 0 because we are already checking b > 0 in if so it does not satisfy that then b will 0 only , no need to set
@algorithmsbyaditi
@algorithmsbyaditi 23 дня назад
Nice suggestion ! Thank you ✨
23 дня назад
Woow , it is a twisted kadane's algo , never would have found out if this video had not popped on my feed !! Thanks a bunch !!
@algorithmsbyaditi
@algorithmsbyaditi 23 дня назад
Glad it helped !
@princekirar4890
@princekirar4890 24 дня назад
For test case : [1,2,8] x = 7 && k = 1 will it work correctly ?
@algorithmsbyaditi
@algorithmsbyaditi 24 дня назад
It will
@animeshchourasia9374
@animeshchourasia9374 24 дня назад
really helpful
@algorithmsbyaditi
@algorithmsbyaditi 24 дня назад
Glad !
@smarthsharda6366
@smarthsharda6366 24 дня назад
i dont think she explained thhe code
@abhisheksharma4900
@abhisheksharma4900 24 дня назад
Your videos are really helpful. First it helps understand the concepts plus it reminds me to get the daily streak, so thank you very much pls keep on making the daily content.
@algorithmsbyaditi
@algorithmsbyaditi 24 дня назад
Glad it was helpful. Efforts will be continued ! ✨
@user-of3ss6hb2l
@user-of3ss6hb2l 24 дня назад
Crisp and clear ! 💯
@algorithmsbyaditi
@algorithmsbyaditi 24 дня назад
Thank youu !
@AlokKumar-gp2jq
@AlokKumar-gp2jq 25 дней назад
it showing wrong answer
@prettyugly_paintings
@prettyugly_paintings 20 дней назад
import java.util.*; class Solution { class Pair{ int node; int weight; Pair(int node, int weight){ this.node = node; this.weight = weight; } } public int secondMinimum(int n, int[][] edges, int time, int change) { ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); for (int i = 0; i <= n; i++) { adj.add(new ArrayList<>()); } for (int[] edge : edges) { adj.get(edge[0]).add(edge[1]); adj.get(edge[1]).add(edge[0]); } int[] distance = new int[n+1]; Arrays.fill(distance, Integer.MAX_VALUE); distance[1] = 0; int[] secDistance = new int[n+1]; Arrays.fill(secDistance, Integer.MAX_VALUE); PriorityQueue<Pair> pq = new PriorityQueue<>((x, y) -> x.weight - y.weight); pq.add(new Pair(1, 0)); while (!pq.isEmpty()) { Pair curr = pq.poll(); int currNode = curr.node; int currTime = curr.weight; if(currNode == n && secDistance[n] != Integer.MAX_VALUE) return secDistance[n]; if ((currTime / change) % 2 == 1) { // Red light currTime = ((currTime/change)+1)*change; } currTime += time; for (int neighbor : adj.get(currNode)) { if(currTime< distance[neighbor]){ secDistance[neighbor] = distance[neighbor]; distance[neighbor] = currTime; pq.add(new Pair(neighbor, currTime)); } else if(currTime> distance[neighbor] && currTime< secDistance[neighbor]){ secDistance[neighbor] = currTime; pq.add(new Pair(neighbor, currTime)); } } } return -1; } }
@tanaysrivastava9303
@tanaysrivastava9303 25 дней назад
Nice explaination ma'am, but can you further explain the code in upcoming videos ,it would be helpful....
@algorithmsbyaditi
@algorithmsbyaditi 25 дней назад
Will improve, Thanks.
@crekso398
@crekso398 25 дней назад
thank you so much ..
@algorithmsbyaditi
@algorithmsbyaditi 25 дней назад
Glad you liked it !
@vedictechyog
@vedictechyog 25 дней назад
Great!
@user-of3ss6hb2l
@user-of3ss6hb2l 25 дней назад
Beautifully explained ! ✨
@algorithmsbyaditi
@algorithmsbyaditi 23 дня назад
Thank you!
@VinayKumar-xs6el
@VinayKumar-xs6el 25 дней назад
sri krishna k naam lekar english mey explain karo
@AlokKumar-gp2jq
@AlokKumar-gp2jq 25 дней назад
shut up
@im_ykp
@im_ykp 25 дней назад
Don't you Know Hindi
@atulwadhwa192
@atulwadhwa192 26 дней назад
Thanks for the video Aditi, because of your video I realised why it's a dp problem and more importantly how we can optimize it. 1-D dp solution [C++] [Memoization] class Solution{ private: bool solve(int ind,string &s,int str_len,unordered_map<string,int> &mp,vector<int> &dp){ if(ind==str_len) return true; if(dp[ind]!=-1) return dp[ind]; for(int i=ind;i<str_len;i++){ if(mp.find(s.substr(ind,i-ind+1))!=mp.end()){ if(solve(i+1,s,str_len,mp,dp)) return dp[ind]=true; } } return dp[ind]=false; } public: bool wordBreak(string s, vector<string>& wordDict) { int size=wordDict.size(); unordered_map<string,int> mp; for(int i=0;i<size;i++) mp[wordDict[i]]=1; int str_len=s.size(); vector<int> dp(str_len+1,-1); return solve(0,s,str_len,mp,dp); } }; PS: You can convert it to tabulation to eliminate aux stack space
@algorithmsbyaditi
@algorithmsbyaditi 25 дней назад
great work !