- 365
- 437 045
codingMohan
India
Приєднався 20 лют 2022
3267. Count Almost Equal Pairs II | Weekly Leetcode 412
Segment Tree Series - bit.ly/segment-trees
DP Playlist - ua-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html
Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html
*************************************************
Contest Link - leetcode.com/contest/weekly-contest-412
Problem Link - leetcode.com/contest/weekly-contest-412/problems/count-almost-equal-pairs-ii/
Solution - leetcode.com/problems/count-almost-equal-pairs-ii/solutions/5689092/video-explanation-optimising-brute-force-solution-using-pre-computation/
*************************************************
Timestamps -
00:00 - Agenda
01:30 - Problem Description
03:30 - Brute Force solution
04:45 - Do we need to perform swap in both "X" and "Y"?
07:08 - Pseudo code & Time Complexity
11:10 - Intuition to optimise
16:00 - # of ways to re-arrange "R"
18:25 - Time Complexity & Pseudo code
21:30 - Code Walkthrough
*************************************************
Interview Experiences Playlists -
Microsoft - ua-cam.com/play/PL9TOCZErLZcOsCBZPQ3uIMzak6gQWG_Kp.html
Amazon - ua-cam.com/play/PL9TOCZErLZcMFSmxoEpNBxvQfWOgRmsfX.html
D.E.Shaw - ua-cam.com/play/PL9TOCZErLZcM8nwVeW4d7JyxcpH175IZ1.html
Linkedin - ua-cam.com/play/PL9TOCZErLZcMN56ITB1IkNUs10QnaEyAe.html
Facebook - ua-cam.com/play/PL9TOCZErLZcNIcaPV8WeHdXHPgAstBf2E.html
*********************************************************************
Please show support and subscribe if you find the content useful.
DP Playlist - ua-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html
Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html
*************************************************
Contest Link - leetcode.com/contest/weekly-contest-412
Problem Link - leetcode.com/contest/weekly-contest-412/problems/count-almost-equal-pairs-ii/
Solution - leetcode.com/problems/count-almost-equal-pairs-ii/solutions/5689092/video-explanation-optimising-brute-force-solution-using-pre-computation/
*************************************************
Timestamps -
00:00 - Agenda
01:30 - Problem Description
03:30 - Brute Force solution
04:45 - Do we need to perform swap in both "X" and "Y"?
07:08 - Pseudo code & Time Complexity
11:10 - Intuition to optimise
16:00 - # of ways to re-arrange "R"
18:25 - Time Complexity & Pseudo code
21:30 - Code Walkthrough
*************************************************
Interview Experiences Playlists -
Microsoft - ua-cam.com/play/PL9TOCZErLZcOsCBZPQ3uIMzak6gQWG_Kp.html
Amazon - ua-cam.com/play/PL9TOCZErLZcMFSmxoEpNBxvQfWOgRmsfX.html
D.E.Shaw - ua-cam.com/play/PL9TOCZErLZcM8nwVeW4d7JyxcpH175IZ1.html
Linkedin - ua-cam.com/play/PL9TOCZErLZcMN56ITB1IkNUs10QnaEyAe.html
Facebook - ua-cam.com/play/PL9TOCZErLZcNIcaPV8WeHdXHPgAstBf2E.html
*********************************************************************
Please show support and subscribe if you find the content useful.
Переглядів: 348
Відео
3266. Final Array State After K Multiplication Operations II | Weekly Leetcode 412
Переглядів 65910 годин тому
Segment Tree Series - bit.ly/segment-trees DP Playlist - ua-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-412 Problem Link - leetcode.com/contest/weekly-contest-412/problems/final-array-state-after-k-multiplication-operations-ii/ Solution - leetcode.com/problems/f...
3250. Find the Count of Monotonic Pairs I | Weekly Leetcode 410
Переглядів 1,3 тис.14 днів тому
Segment Tree Series - bit.ly/segment-trees DP Playlist - ua-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link -leetcode.com/contest/weekly-contest-410/problems/find-the-count-of-monotonic-pairs-i/ Solution - leetcode.com/problems/find-the-count-of-mon...
3251. Find the Count of Monotonic Pairs II | Weekly Leetcode 410
Переглядів 1,8 тис.14 днів тому
Segment Tree Series - bit.ly/segment-trees DP Playlist - ua-cam.com/play/PL9TOCZErLZcNxIHWVRcJbVTvgRgLFcgHC.html Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link -leetcode.com/contest/weekly-contest-410/problems/find-the-count-of-monotonic-pairs-ii/ Solution - leetcode.com/problems/find-the-count-of-mo...
3245. Alternating Groups III | Weekly Leetcode 409
Переглядів 1,2 тис.21 день тому
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link - leetcode.com/contest/weekly-contest-409/problems/alternating-groups-iii/description/ Solution - leetcode.com/problems/alternating-groups-iii/solutions/5585945/video-explanation-starting-from-brute-force-and-op...
3244. Shortest Distance After Road Addition Queries II | Weekly Leetcode 409
Переглядів 1 тис.21 день тому
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-409 Problem Link - leetcode.com/contest/weekly-contest-409/problems/shortest-distance-after-road-addition-queries-ii/description/ Solution - leetcode.com/problems/shortest-distance-after-road-addition-queries-ii/solutions/558407...
3235. Check if the Rectangle Corner Is Reachable | Weekly Leetcode 408
Переглядів 1 тис.28 днів тому
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-408 Problem Link - leetcode.com/contest/weekly-contest-408/problems/check-if-the-rectangle-corner-is-reachable/ Solution - leetcode.com/problems/check-if-the-rectangle-corner-is-reachable/solutions/5547478/video-explanation-intu...
3234. Count the Number of Substrings With Dominant Ones | Weekly Leetcode 408
Переглядів 4,1 тис.28 днів тому
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-408 Problem Link - leetcode.com/contest/weekly-contest-408/problems/count-the-number-of-substrings-with-dominant-ones/ Solution - leetcode.com/problems/count-the-number-of-substrings-with-dominant-ones/solutions/5546880/video-ex...
3225. Maximum Score From Grid Operations | Leetcode Biweekly 135
Переглядів 1,4 тис.Місяць тому
Segment Tree Series - bit.ly/segment-trees Contest Link - leetcode.com/contest/biweekly-contest-135/ Problem Link - leetcode.com/contest/biweekly-contest-135/problems/maximum-score-from-grid-operations/description/ Solution - leetcode.com/problems/maximum-score-from-grid-operations/solutions/5517272/video-explanation-journey-of-o-r-4-c-o-r-3-c-o-r-r-c/ Timestamps - 00:00 - Agenda 01:09 - Proble...
3229. Minimum Operations to Make Array Equal to Target | Weekly Leetcode 407
Переглядів 681Місяць тому
Segment Tree Series - bit.ly/segment-trees Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-407 Problem Link - leetcode.com/contest/weekly-contest-407/problems/minimum-operations-to-make-array-equal-to-target/description/ Solution - leetcode.com/problems/minimum-operations-to-make-array-equal-to-target/solutions/551014...
3218. Minimum Cost for Cutting Cake I | Weekly Leetcode 406
Переглядів 390Місяць тому
Full Video - ua-cam.com/video/LsICVuKNQoE/v-deo.html Segment Tree Series - bit.ly/segment-trees Hashing Problems - 1. ua-cam.com/video/8kMq8WyCpj0/v-deo.html 2. ua-cam.com/video/1thnThrIzwg/v-deo.html 3. ua-cam.com/video/hRd3ZlTBkEs/v-deo.html Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-406 Problem Link - leetcode...
3219. Minimum Cost for Cutting Cake II | Weekly Leetcode 406
Переглядів 364Місяць тому
Segment Tree Series - bit.ly/segment-trees Hashing Problems - 1. ua-cam.com/video/8kMq8WyCpj0/v-deo.html 2. ua-cam.com/video/1thnThrIzwg/v-deo.html 3. ua-cam.com/video/hRd3ZlTBkEs/v-deo.html Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-406 Problem Link - leetcode.com/contest/weekly-contest-406/problems/minimum-cost...
3213. Construct String with Minimum Cost | Weekly Leetcode 405
Переглядів 989Місяць тому
Segment Tree Series - bit.ly/segment-trees Similar Hashing Problems - 1. ua-cam.com/video/8kMq8WyCpj0/v-deo.html 2. ua-cam.com/video/1thnThrIzwg/v-deo.html 3. ua-cam.com/video/hRd3ZlTBkEs/v-deo.html Hashing Playlist - ua-cam.com/play/PL9TOCZErLZcPVi_Nt-bHCwH9GtV-nz93c.html Contest Link - leetcode.com/contest/weekly-contest-405 Problem Link - leetcode.com/contest/weekly-contest-405/problems/cons...
3209. Number of Subarrays With AND Value of K | Leetcode Biweekly 134
Переглядів 644Місяць тому
Segment Tree Series - bit.ly/segment-trees Contest Link - leetcode.com/contest/biweekly-contest-134/ Problem Link - leetcode.com/contest/biweekly-contest-134/problems/number-of-subarrays-with-and-value-of-k/ Solution - leetcode.com/problems/number-of-subarrays-with-and-value-of-k/solutions/5433480/video-explanation-with-all-the-required-proof-involved/ Timestamps - 00:00 - Agenda 00:49 - Proble...
3212. Count Submatrices With Equal Frequency of X and Y | Weekly Leetcode 405
Переглядів 1,2 тис.Місяць тому
Segment Tree Series - bit.ly/segment-trees Another Interesting 2D Prefix Sum Application - ua-cam.com/video/AyYAcAL2cmI/v-deo.html Contest Link - leetcode.com/contest/weekly-contest-405 Problem Link - leetcode.com/contest/weekly-contest-405/problems/count-submatrices-with-equal-frequency-of-x-and-y/ Solution - leetcode.com/problems/count-submatrices-with-equal-frequency-of-x-and-y/solutions/543...
3202. Find the Maximum Length of Valid Subsequence II | Weekly Leetcode 404
Переглядів 1,3 тис.Місяць тому
3202. Find the Maximum Length of Valid Subsequence II | Weekly Leetcode 404
3203. Find Minimum Diameter After Merging Two Trees | Weekly Leetcode 404
Переглядів 529Місяць тому
3203. Find Minimum Diameter After Merging Two Trees | Weekly Leetcode 404
3197. Find the Minimum Area to Cover All Ones II | Weekly Leetcode 403
Переглядів 9952 місяці тому
3197. Find the Minimum Area to Cover All Ones II | Weekly Leetcode 403
3186. Maximum Total Damage With Spell Casting | Weekly Leetcode 402
Переглядів 8272 місяці тому
3186. Maximum Total Damage With Spell Casting | Weekly Leetcode 402
3187. Peaks in Array | Weekly Leetcode 402
Переглядів 5442 місяці тому
3187. Peaks in Array | Weekly Leetcode 402
3170. Lexicographically Minimum String After Removing Stars | Weekly Leetcode 400
Переглядів 3932 місяці тому
3170. Lexicographically Minimum String After Removing Stars | Weekly Leetcode 400
3171. Find Subarray With Bitwise AND Closest to K | 2 different Approaches | Weekly Leetcode 400
Переглядів 1,2 тис.2 місяці тому
3171. Find Subarray With Bitwise AND Closest to K | 2 different Approaches | Weekly Leetcode 400
3165. Maximum Sum of Subsequence With Non-adjacent Elements | Bonus Qs + Hint | Weekly Leetcode 399
Переглядів 1,4 тис.3 місяці тому
3165. Maximum Sum of Subsequence With Non-adjacent Elements | Bonus Qs Hint | Weekly Leetcode 399
3164. Find the Number of Good Pairs II | 2 Approaches | Weekly Leetcode 399
Переглядів 9983 місяці тому
3164. Find the Number of Good Pairs II | 2 Approaches | Weekly Leetcode 399
3154. Find Number of Ways to Reach the K-th Stair | Weekly Leetcode 398
Переглядів 4073 місяці тому
3154. Find Number of Ways to Reach the K-th Stair | Weekly Leetcode 398
3145. Find Products of Elements of Big Array | Leetcode Biweekly 130
Переглядів 1,1 тис.3 місяці тому
3145. Find Products of Elements of Big Array | Leetcode Biweekly 130
3149. Find the Minimum Cost Array Permutation | Weekly Leetcode 397
Переглядів 1 тис.3 місяці тому
3149. Find the Minimum Cost Array Permutation | Weekly Leetcode 397
3148. Maximum Difference Score in a Grid | Top Down + Bottom Up | Weekly Leetcode 397
Переглядів 1,4 тис.3 місяці тому
3148. Maximum Difference Score in a Grid | Top Down Bottom Up | Weekly Leetcode 397
3144. Minimum Substring Partition of Equal Character Freqcy | HARDER VERSION | Leetcode Biweekly 130
Переглядів 7013 місяці тому
3144. Minimum Substring Partition of Equal Character Freqcy | HARDER VERSION | Leetcode Biweekly 130
3139. Minimum Cost to Equalize Array | Weekly Leetcode 396
Переглядів 8863 місяці тому
3139. Minimum Cost to Equalize Array | Weekly Leetcode 396
a great, easy to follow and comprehensive explanation 🔥
Great Explanation!
very nice and clear explanation , thanks :)
const int N = 1e7; int freq[N]; class Solution { public: int countPairs(vector<int>& nums) { int n = nums.size(); memset(freq, 0, sizeof(freq)); int cnt = 0; for(int i = 0; i < n; i++) { // unique numbers that can be created after swaping nums[i] atmost twice cnt += freq[nums[i]]; unordered_set<int> diff_nums; string digits = to_string(nums[i]); if(digits.size() < 7) { int to_add = 7 - digits.size(); string temp = ""; while(to_add--) { temp += '0'; } digits = temp + digits; } // 1 or 2 swaps allowed for(int l1 = 0; l1 < 7; l1++) { for(int r1 = l1+1; r1 < 7; r1++) { // 1 swap swap(digits[l1],digits[r1]); diff_nums.insert(stoi(digits)); swap(digits[l1],digits[r1]); for(int l2 = 0; l2 <7;l2++) { for(int r2 = l2+1; r2 < 7; r2++) { // 2 swap swap(digits[l1],digits[r1]); swap(digits[l2],digits[r2]); diff_nums.insert(stoi(digits)); swap(digits[l2],digits[r2]); swap(digits[l1],digits[r1]); } } } } for(auto it : diff_nums) { freq[it]++; } } return cnt; } }; I written the code using string and stoi method, but getting TLE at 629/630 test cases...
leetcode weekly contest 411 ques D, can you discuss please
How can we use merge tree to solve number of different elements in a segment
Thank you, great explanation!
sir not able to understand whats wrong in my code class Solution { public: const int MOD = 1000000000+7; long long power_mod(long long base, long long exp) { long long result = 1; while (exp > 0) { if (exp % 2 == 1) { result = (result * base) % MOD; } base = (base * base) % MOD; exp = exp / 2; } return result; } vector<int> getFinalState(vector<int>& nums, int k, int multiplier) { if(multiplier ==1) return nums; priority_queue<pair<long long , int>, vector<pair<long long , int>>, greater<>> minHeap; int initialMaximum =0 ; int initialMaximumIndex = -1; for(int i=0 ;i<nums.size();i++ ) { minHeap.push({nums[i],i}); initialMaximum = max(initialMaximum,nums[i]); if(nums[i] > initialMaximum) { initialMaximum = nums[i]; initialMaximumIndex = i; } } while(k> 0 && minHeap.top().first*multiplier <= initialMaximum) { long long mini = minHeap.top().first; int miniIndex = minHeap.top().second; mini = (multiplier * mini) %MOD; minHeap.pop(); minHeap.push({mini,miniIndex}); k--; } int cyclePosition = k/nums.size();// zero based index position int remainingCount = k%nums.size(); long long multiplierKiPowerKaResult = power_mod(multiplier,cyclePosition); while(minHeap.size() > 0) { nums[minHeap.top().second]=(minHeap.top().first*multiplierKiPowerKaResult)%MOD; minHeap.pop(); } for(int i=0 ;i<nums.size();i++) { minHeap.push({nums[i],i}); } for(int i=1 ;i<=remainingCount;i++) { int mini = (minHeap.top().first * multiplier) %MOD; int minIndex = minHeap.top().second; minHeap.pop(); minHeap.push({mini,minIndex}); } while(minHeap.size() >0) { nums[minHeap.top().second] = (minHeap.top().first); minHeap.pop(); } return nums; } };
Perfect explanation by the way
Well made video
So good video. Crystal clear. Please continue making such type of videos very helpful
Can we solve it using disjoint set? Really tried hard but failed at 604/630
What was your approach?
@codingmohan I did a double for loop for all possible pairs of numbers in nums as stated in the question. Then, I used a checker function (x,y) which increments my answer by 1 if it's true. Now, what my checker function does is to initialize a disjoint set of size 7, iterates through the numbers while comparing them at each position. If they are different and don't belong to the same parent, then I united them E.g (4598, 5489) 4 and 5 is different and so I merge them 5 and 4 is different but they already belong to the same group 9 and 8 is different so I merge 8 and 9 is different but they are already merged so I skip I know the approach is buggy but I was wondering why disjoint set won't work
THIS QUALITY CONTENT >>>>>>>
First viewer🥰, but sir quality is upto 360p only
It takes some time for UA-cam to process video in higher formats. It should be all good now.
Overwhelmed by the explanation :)
Great Solution Bhaiya..
bro mohan is your real name?
My real name is Subham.
@@codingmohanall hail king Subham
god's work
thnxx keep going.
thank you
thank mohan, for this much-needed video i really appreciate it
Nice video. Liked the way you teach things slowly
Can you tell me about your pratice strategy from beginner to leetcode master ?
Great Solution Sir......
can we apply dfs here?
Instead of set for grouping based on index what can be used in Java?
thank you for making such amazing videos....
Accepted
Nice as usual Please when are you dropping next videos?
This channel is treasures. Thank you very much
Best explanation
Great lecture
Can you also explain the last problem from the biweekly 136 contests last problem that is using tree rerouting[DP on Trees] would love to see your explanation on that topic :)
TOP notch content
excellent sir
For each row of your time complexity analysis you are keeping V1i constant. But you are not considering the "cnt" part of your pseudo code wherein you will need to iterate over the bucket of each V1i and V2i pair.
Thanks that condition make this problem easy. Solved it after watching half video.
very nice explanation, thanks
please xplain how you are handling the overflows. Why you are adding the mod while getting the range sum.
For overflows - I am making sure I take mod on every addition so that the number never goes beyond given MOD. Why I am subtracting - because every number is modulus M, the left part can be smaller than the right. And you cannot use negative number with mod, hence I added mod (as adding mod is equal to adding zero if you take MOD).
bhai last 10 min khud bolke khud smjh liya aapne
Top notch explanation <3
Great explanation...keep up the good work
Thanku bhaiya very good explanation