Rotating the Box (Leetcode 1861)
20:52
Even Odd Tree (Leetcode 1609)
24:28
4 жыл бұрын
Word Search II (Leetcode 212)
30:00
4 жыл бұрын
The kth Factor of n  (Leetcode 1492)
12:04
Mock Interview Session 1 (Easy)
7:49
Hamming Distance (Leetcode 461)
10:31
Single Number II (Leetcode 137)
19:27
Пікірлер
@siddhanthsridhar4742
@siddhanthsridhar4742 4 ай бұрын
placement?
@Anonymous____________A721
@Anonymous____________A721 4 ай бұрын
?
@architagarwal7379
@architagarwal7379 5 ай бұрын
According to editorial of leet code this can be optimised to O(n*log(sumof elements)) No one on entire youtube is discussin this approach sab easy easy approach likh rahe hai
@mrf92
@mrf92 11 ай бұрын
Time complexity calculation is wrong. you skipped the cost of sorting a (n*(n+1))/2 sized array. which would be O(n^2 log(n^2)). So total time complexity will be O(n^2log(n^2)). I think time/space complexity-wise your approach 2 is no better than approach 1.
@shaurya478
@shaurya478 Жыл бұрын
line: 18 is wrong, zero[i] = c1 shoud be outside the if block.
@redline_ghatak
@redline_ghatak Жыл бұрын
why do we need this mod over here?
@sanjithchidhirala3116
@sanjithchidhirala3116 Жыл бұрын
Comment section has more factful information than video😂
@SANDEEPKUMAR-fs1tt
@SANDEEPKUMAR-fs1tt Жыл бұрын
muh utha kr video daldi ....... phle solution cla kr to dekhlia kro
@WiFiWaLaaa
@WiFiWaLaaa Жыл бұрын
//ALL TC IS PASSED class Solution { public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) { Queue<Integer> q = new LinkedList<>(); HashSet<Integer> hs = new LinkedHashSet<>(); int[] indegree = new int[n]; for (int i = 0; i < n; i++) { if (leftChild[i] != -1) indegree[leftChild[i]]++; if (rightChild[i] != -1) indegree[rightChild[i]]++; } int rootCount = 0; int root = -1; for (int i = 0; i < n; i++) { if (indegree[i] == 0) { rootCount++; root = i; } if (rootCount > 1) return false; } if (root == -1) return false; q.add(root); while (!q.isEmpty()) { int curr = q.remove(); if (hs.contains(curr)) return false; hs.add(curr); if (leftChild[curr] != -1) q.add(leftChild[curr]); if (rightChild[curr] != -1) q.add(rightChild[curr]); } return hs.size() == n; } }
@Anuj-vf7bg
@Anuj-vf7bg Жыл бұрын
worst way to waste time
@WiFiWaLaaa
@WiFiWaLaaa Жыл бұрын
class Solution { public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) { Queue<Integer> q = new LinkedList<>(); HashSet<Integer> hs = new LinkedHashSet<>(); int[] indegree = new int[n]; for (int i = 0; i < n; i++) { if (leftChild[i] != -1) indegree[leftChild[i]]++; if (rightChild[i] != -1) indegree[rightChild[i]]++; } int rootCount = 0; int root = -1; for (int i = 0; i < n; i++) { if (indegree[i] == 0) { rootCount++; root = i; } if (rootCount > 1) return false; } if (root == -1) return false; q.add(root); while (!q.isEmpty()) { int curr = q.remove(); if (hs.contains(curr)) return false; hs.add(curr); if (leftChild[curr] != -1) q.add(leftChild[curr]); if (rightChild[curr] != -1) q.add(rightChild[curr]); } return hs.size() == n; } }
@atishaykumar6006
@atishaykumar6006 Жыл бұрын
first find the root node then do the same as above. unordered_map< int, int > mp; queue< int > q; vector< bool > rootArr(n, 1); for(int i=0; i<n; i++) { if(leftChild[i] != -1) rootArr[leftChild[i]] = false; if(rightChild[i] != -1) rootArr[rightChild[i]] = false; } int count = 0; int root = 0; for(int i=0; i<n; i++) { if(rootArr[i] == true) { count++; root = i; } } if(count > 1) return false; q.push(root); while(!q.empty()) { int node = q.front(); q.pop(); if(mp.find(node) != mp.end()) return false; mp[node]++; if(leftChild[node] != -1) q.push(leftChild[node]); if(rightChild[node] != -1) q.push(rightChild[node]); } return mp.size() == n;
@Mihir_kathpal
@Mihir_kathpal Жыл бұрын
wrong solution
@WiFiWaLaaa
@WiFiWaLaaa Жыл бұрын
class Solution { public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) { Queue<Integer> q = new LinkedList<>(); HashSet<Integer> hs = new LinkedHashSet<>(); int[] indegree = new int[n]; for (int i = 0; i < n; i++) { if (leftChild[i] != -1) indegree[leftChild[i]]++; if (rightChild[i] != -1) indegree[rightChild[i]]++; } int rootCount = 0; int root = -1; for (int i = 0; i < n; i++) { if (indegree[i] == 0) { rootCount++; root = i; } if (rootCount > 1) return false; } if (root == -1) return false; q.add(root); while (!q.isEmpty()) { int curr = q.remove(); if (hs.contains(curr)) return false; hs.add(curr); if (leftChild[curr] != -1) q.add(leftChild[curr]); if (rightChild[curr] != -1) q.add(rightChild[curr]); } return hs.size() == n; } }
@ganeshbunny2689
@ganeshbunny2689 Жыл бұрын
n = 4 leftChild = [3,-1,1,-1] rightChild = [-1,-1,0,-1] Output false Expected true explain me about this
@WiFiWaLaaa
@WiFiWaLaaa Жыл бұрын
class Solution { public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) { Queue<Integer> q = new LinkedList<>(); HashSet<Integer> hs = new LinkedHashSet<>(); int[] indegree = new int[n]; for (int i = 0; i < n; i++) { if (leftChild[i] != -1) indegree[leftChild[i]]++; if (rightChild[i] != -1) indegree[rightChild[i]]++; } int rootCount = 0; int root = -1; for (int i = 0; i < n; i++) { if (indegree[i] == 0) { rootCount++; root = i; } if (rootCount > 1) return false; } if (root == -1) return false; q.add(root); while (!q.isEmpty()) { int curr = q.remove(); if (hs.contains(curr)) return false; hs.add(curr); if (leftChild[curr] != -1) q.add(leftChild[curr]); if (rightChild[curr] != -1) q.add(rightChild[curr]); } return hs.size() == n; } }
@ersoumyajitpan7205
@ersoumyajitpan7205 Жыл бұрын
wrong solution Input n = 4 leftChild = [3,-1,1,-1] rightChild = [-1,-1,0,-1] Use Testcase Output false Expected true
@Devender-Verma
@Devender-Verma Жыл бұрын
Here is Correct code with impovement of this testcase 4 [3,-1,1,-1] [3,-1,1,-1] ``` class Solution { public: int findroot(int n, vector<int>& leftChild, vector<int>& rightChild){ vector<bool> visited(n, false); // visit the both array and tick true for(int i=0; i<n; i++){ if(leftChild[i] != -1) visited[leftChild[i]] = true; if(rightChild[i] != -1) visited[rightChild[i]] = true; } int root = -1; // find the index where it's false, it will be the root which has no parent, for(int i=0; i<n; i++){ if(root == -1 and visited[i] == false){ root = i; // if found more than 1 false index it means more than 1 parent exist, then simlpy return false }else if(visited[i] == false){ return -1; } } return root; } bool validateBinaryTreeNodes(int n, vector<int>& leftChild, vector<int>& rightChild) { queue<int> q; set<int> hs; int root = findroot(n, leftChild, rightChild); // had more then 1 parent or cycle so return false if(root == -1) return false; q.push(root); while(!q.empty()){ int node = q.front(); q.pop(); if(hs.find(node) != hs.end()){ return false; } hs.insert(node); if(leftChild[node] != -1){ q.push(leftChild[node]); } if(rightChild[node] != -1){ q.push(rightChild[node]); } } return hs.size() == n; } }; ```
@sourabh258
@sourabh258 Жыл бұрын
Good explanation, here is one with greedy approach: public int movesToMakeZigzag(int[] nums) { int evenMoves=0,oddMoves=0; for(int i=0;i<nums.length;i++){ int left = i-1 < 0? Integer.MAX_VALUE:nums[i-1]; int curr = nums[i]; int right= i+1>=nums.length?Integer.MAX_VALUE:nums[i+1]; int min=Math.min(left,right); if(i%2==0) evenMoves+= curr-min>=0? curr-min+1:0; else oddMoves+= curr-min>=0? curr-min+1:0; } return Math.min(evenMoves,oddMoves); }
@Priyanka-ye6zt
@Priyanka-ye6zt Жыл бұрын
c++ solution int maxNumberOfFamilies(int n, vector<vector<int>>& reservedSeats) { unordered_map<int, vector<int>> mp; int totalCount = n*2; for(int i=0; i<reservedSeats.size(); i++){ mp[reservedSeats[i][0]].push_back(reservedSeats[i][1]); } for(auto &m: mp){ int dec=0; vector<int> p = m.second; if(find(p.begin(), p.end(), 2) != p.end() ||find(p.begin(), p.end(), 3) != p.end() || find(p.begin(), p.end(),4) != p.end() || find(p.begin(), p.end(), 5) != p.end() ){ dec++; totalCount--; } if(find(p.begin(), p.end(), 6) != p.end() ||find(p.begin(), p.end(), 7) != p.end() || find(p.begin(), p.end(),8) != p.end() || find(p.begin(), p.end(), 9) != p.end() ){ dec++; totalCount--; } if(find(p.begin(), p.end(), 4) == p.end() && find(p.begin(), p.end(), 5) == p.end() && find(p.begin(), p.end(),6) == p.end() && find(p.begin(), p.end(), 7) == p.end() ){ if(dec == 2) totalCount++; } } return totalCount; }
@curesnow6493
@curesnow6493 Жыл бұрын
Thank you, your solution is very helpful.
@arpitkesarwani8071
@arpitkesarwani8071 2 жыл бұрын
why we are doing arr[i-k] to delete first element??
@SG-tt4pg
@SG-tt4pg 2 жыл бұрын
Thanks, the volume is toooo low
@lloydlasrado
@lloydlasrado 2 жыл бұрын
good detail explanation. please keep it up same way
@rahulkumar6726
@rahulkumar6726 2 жыл бұрын
It was really helpful
@kabilduke2000
@kabilduke2000 2 жыл бұрын
In java return Integer.parseInt(String.valueOf(num).replaceFirst("6","9"));
@qazaqempire3828
@qazaqempire3828 2 жыл бұрын
for this problem this is better video than others
@krishnagarg2060
@krishnagarg2060 2 жыл бұрын
this code is not valid if in a one row only seat no. 8 is reservd
@JitendraKumar-ti6yd
@JitendraKumar-ti6yd 2 жыл бұрын
Awesome bro!
@udhayachandhar4770
@udhayachandhar4770 2 жыл бұрын
suffle is not creating new array and modifying the existing
@munendragaur4965
@munendragaur4965 2 жыл бұрын
Bsdk apni original awaj me samja na angrej kyu ban raha he
@haoyucheng5401
@haoyucheng5401 2 жыл бұрын
not going to work if you are using set, cause it is possible for two trans to be the same, and we need them both in final answer.
@carlosj.castillo254
@carlosj.castillo254 2 жыл бұрын
thnks
@ravimane5508
@ravimane5508 2 жыл бұрын
this code is not running ,it giving an error that- expected ) in foreach(var kvp in map). I copied the code from the github link you provided in the comments.
@pecan8470
@pecan8470 2 жыл бұрын
thank you
@rahulpothula1902
@rahulpothula1902 2 жыл бұрын
Can anyone pls find out the error (logical) in my smaallll code?: class Solution { public: int tupleSameProduct(vector<int>& nums) { int n = nums.size(); vector<int> hash(1e8, 0); int ans = 0; for(int i = 0; i < n - 1; i++) { for(int j = i + 1; j < n; j++) { int ind = nums[i] * nums[j]; hash[ind]++; if(hash[ind] >= 2) ans += 8; } } return ans; } };
@karannnful
@karannnful 2 жыл бұрын
horrible
@AyushRaj-pm1dz
@AyushRaj-pm1dz 2 жыл бұрын
C++ Code : int minFlips(int a, int b, int c) { int count=0; while(c || a || b){ if(c&1){ if((a&1)==0 && (b&1)==0) count++; } else{ if(a&1) count++; if(b&1) count++; } //moving through the bits right to left a >>= 1; b >>= 1; c >>= 1; } return count; }
@supratimbhattacharjee5324
@supratimbhattacharjee5324 2 жыл бұрын
class Solution { public: bool validateBinaryTreeNodes(int n, vector<int>& leftChild, vector<int>& rightChild) { int root=-1; int count=0; vector<int> adj[n]; vector<int> indeg(n,0); vector<bool> vis(n,false); queue<int> q; for(int i=0;i<n;i++) { if(leftChild[i]!=-1) { adj[i].push_back(leftChild[i]); indeg[leftChild[i]]++; } if(rightChild[i]!=-1) { adj[i].push_back(rightChild[i]); indeg[rightChild[i]]++; } } for(int i=0;i<n;i++) { if(!indeg[i]) { count++; root=i; } } if(count>1 || root==-1) return false; q.push(root); vis[root]=true; while(!q.empty()) { int curNode=q.front(); q.pop(); for(auto x: adj[curNode]) { if(vis[x]) return false; q.push(x); vis[x]=true; } } for(int i=0;i<n;i++) if(!vis[i]) return false; return true; } };
@madhavchittlangia7044
@madhavchittlangia7044 2 жыл бұрын
Nice Explanation
@ishwaraggarwal7851
@ishwaraggarwal7851 2 жыл бұрын
Same solution after finding the root node. public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) { //kzbin.info/www/bejne/qoKaqpaOrbNpepo //Declare set to find unique node in Tree Set<Integer> uniqueNode = new HashSet(); for(int left : leftChild){ if(left!=-1) uniqueNode.add(left); } for(int right : rightChild){ if(right!=-1) uniqueNode.add(right); } //If any node is not child of any other node means it's root. int rootNode = -1; for(int i=0; i<n; i++){ if(uniqueNode.contains(i)) continue; rootNode = i; break; } if(rootNode==-1){ return false; } Queue<Integer> queue = new LinkedList(); Set<Integer> visitedSet = new HashSet(); //Adding root in queue queue.add(rootNode); while(!queue.isEmpty()){ int size = queue.size(); while(size>0){ int node = queue.poll(); if(visitedSet.contains(node)) return false; visitedSet.add(node); if(leftChild[node]!=-1){ queue.add(leftChild[node]); } if(rightChild[node]!=-1){ queue.add(rightChild[node]); } size--; } } return visitedSet.size()==n; }
@ani68
@ani68 2 жыл бұрын
The explaination was awesome....💯
@Ryan-fe2du
@Ryan-fe2du 2 жыл бұрын
Should this be time: O(n + m)? Because you looped twice on each?
@dhanashreegodase4445
@dhanashreegodase4445 3 жыл бұрын
Thanku
@mdmusadali9159
@mdmusadali9159 3 жыл бұрын
Hi
@mashab9129
@mashab9129 3 жыл бұрын
cool question and great walk through, thank you so much for sharing your knowledge!
@kirant5548
@kirant5548 3 жыл бұрын
woow. really nice solution and explained well too 😃
@jasmeenkaur6001
@jasmeenkaur6001 3 жыл бұрын
Why we do in opposite direction????
@vishruthreddy7078
@vishruthreddy7078 3 жыл бұрын
what if q queries are given like a range of l to r how will you solve this?
@molyoxide8358
@molyoxide8358 2 жыл бұрын
what is l and r here?
@mashab9129
@mashab9129 3 жыл бұрын
great walktrhough. thanks for sharing.
@MOHITRANA-to7rf
@MOHITRANA-to7rf 3 жыл бұрын
thank you
@AlbertoRodriguez-oe6jo
@AlbertoRodriguez-oe6jo 3 жыл бұрын
Feels like you're reading the solution off the book or something. You could explain better with pen and paper.
@nikunjjain4997
@nikunjjain4997 3 жыл бұрын
Really simple code and explanation . Great work 👍
@arijitroy8390
@arijitroy8390 3 жыл бұрын
Bhai tu ye fake accent mat kiya kar. Isliye dislikes zyada h tere video me
@arnabpersonal6729
@arnabpersonal6729 3 жыл бұрын
This is not an expected solution in an interview we have to do a lazy increment ie increment only during pop if that element is within bottom k
@vasujhawar.6987
@vasujhawar.6987 Жыл бұрын
teach me that
@vasujhawar.6987
@vasujhawar.6987 Жыл бұрын
looking for a video on that