Hey bro, I hope you had an incredible trip! I just want to take a moment to thank you for everything you're doing. I currently work at TCS with a very low package, but your support has really motivated and inspired me. I'm feeling super pumped, and I hope to transition to a better company soon. Thanks again for everything, Mik. I truly pray that all your dreams come true.
Bhaiya i have been following you for last two months and i could see growth in my problem solving ability. Thankyou so much for providing us with the intuitiveness to solve the questions. If possible then please cover the leetcode and codechef contests as well.
Sir, your code of minimum_no_of_swaps function used in this code fails for one testcase in gfg problem: minimum no. of swaps to sort an array at last 1111th test case, could you please tell why it happen because it works correctly for leetcode, It would be very helpful sir
I am solving questions, working hard..still I am only facing rejections..either my code doesn't run or ques becomes too tricky.... my luck doesn't play well...I am very demotivated.
bhaiya no of swap dekhne ke liye kyu na ham given array ko sorted array se compare kr le like jis index pe number different honge us samay count++ kar denge and at last count/2 kar denge kyuki jis number se swap hua usme bhi to count++ hoga so is type se number of swap nikal jyega !!
Here's my Solution: class Solution { public: int minSwapsToSort(vector& arr) { int n = arr.size(); vector arrWithIndex(n); // Pair array elements with their indices for (int i = 0; i < n; i++) { arrWithIndex[i] = {arr[i], i}; } // Sort the array by element values sort(arrWithIndex.begin(), arrWithIndex.end()); vector visited(n, false); // To keep track of visited elements int swaps = 0; for (int i = 0; i < n; i++) { // If already visited or in the correct position, skip if (visited[i] || arrWithIndex[i].second == i) { continue; } // Count the size of the cycle int cycleSize = 0; int current = i; while (!visited[current]) { visited[current] = true; current = arrWithIndex[current] .second; // Move to the next index in the cycle cycleSize++; } // If there is a cycle of size > 1, it contributes (size - 1) swaps if (cycleSize > 1) { swaps += (cycleSize - 1); } } return swaps; } int minimumOperations(TreeNode* root) { // At Same Level, so we'll go with BFS queue q; q.push(root); int ans = 0; while (!q.empty()) { int size = q.size(); vector treeNodeVals; for (int i = 0; i < size; i++) { TreeNode* temp = q.front(); q.pop(); if (temp->left != NULL) { treeNodeVals.push_back(temp->left->val); q.push(temp->left); } if (temp->right != NULL) { treeNodeVals.push_back(temp->right->val); q.push(temp->right); } } ans += minSwapsToSort(treeNodeVals); } return ans; } };
ham 2nd type wala bfs kb lagate hai ? koi video hai aapki jismai specifically apne ye bataya ho? when we use first one and when we use 2nd one BFS aur agar ham hamesha size wala BFS use kre to galti hogi kya?
Hi MIK, the function of "Minimum Swaps to sort" doesn't work and gives wrong answer on GFG site on the last test case. could you please let me know why?
Bhaia maine abhi dsa seekhna start hi kara hain. please aap muje bata do ki main apke channel ka use kaise karun effeciently. main pahle ek topic ka theory dekh lu fir usi topic ki jo playlist apne banyi hain usme se questions karuun. Please thoda detail main samja do maine apka chaneel 1 week pahle hi discover kara hain itni saari vedios hain har playlist main mujhe dekh kar samaj nahi aa raha haiin kaise padhu unse
aise to kai videos me bataya hai sir ne is BFS waali cheez ko but latest ek video aai thi sir ki "Reverse Odd Levels of Binary Tree" - Leetcode-2415 usme bataya tha fir se .
bhaiya ye sb to bn jata h, please thoda contests k b questions dekheye na, audience for that will be large too ! and we need it. please. the question MAXIMIZE AMOUNT AFTER TWO DAYS OF CONVERSION had me long to think and likewise.
Bhaiya mene ye code khud se likha h or jab dry run kia tha to ye code 3ino test cases k liye pass ho rha tha pr jab editor pr run kia to ye ek b test cases pass ni kr pa rha . Kya ap bta sakte h is question ko ese kyu ni kr sakte Code --> int minimumOperations(TreeNode* root) { int count = 0; queue que; que.push(root); while (!que.empty()) { int n = que.size(); vector vec; while (n--) { auto curr = que.front(); que.pop(); vec.push_back(curr); if (curr->left != NULL) { que.push(curr->left); } if (curr->right != NULL) { que.push(curr->right); } } int l = 0; int r = vec.size() - 1; while (l < r) { if (vec[l]->val > vec[r]->val) { auto temp = vec[l]->val; vec[l]->val = vec[r]->val; vec[r]->val = temp; l++; count++; } else { r--; } } } return count; }
int solve(vector &v){ int swaps=0,n=v.size(); vectortemp=v; sort(begin(temp),end(temp)); unordered_mapmp; for(int i=0;ileft); if(it->right) q.push(it->right); } ans+=solve(v); } return ans; } my solution. important cheez thi min swaps to get array sorted jo wo decode kr liya smjho question ho gya.. or yahi maine codeforces pe solve kri thi..
Hello bhaiya kaise ho aap, Bhaiya mujhse ek help chahiye thi aapse plz 🙏 meyne bahut try Kiya but kahi nhi hua, bhaiya final year ke liye project banana hai to uske liye pahle guide registration karna hai and mujhse koi nahi mil rha hai, requirement for guide is ( btech + 5 year experience in job / teaching). Bhaiya aap kisi ko bologe ya phir aapke contact mey koi hoto plz contact kardo, college mey jab tak guide registration nahi karunga tab tak aage proceed nhi kar sakta, bas formality karna hai bhaiya only guide ka details submit karna hai bas itna plz bhaiya help me 🙏🙏🙏🙏
Hey bro, I hope you had an incredible trip! I just want to take a moment to thank you for everything you're doing. I currently work at TCS with a very low package, but your support has really motivated and inspired me. I'm feeling super pumped, and I hope to transition to a better company soon. Thanks again for everything, Mik. I truly pray that all your dreams come true.
You got this bro. I am also in a similar path and got a job in a service based company and now preparing for product based company. Let's do this.
@@gui-codes we got this bro , let's gooooo
All the best buddy.
Let’s do this 🔥🔥🔥
Radhe Radhe ❤❤
finally after few days mik sir is back✅✅
The LEGEND is back 🔥
Waited eagerly to see your videos.
I am done BRUTE FORCE
BFS + Selection Sort Thank you you are back ❤❤❤❤
Please continue DP CONCEPT WALA PLAYLIST 🙏🙏🙏
Finally MIK sir is back ❤️
Sir ho sake to kal wala potd karado copy paste kiya tha kal wala 😅
I solved it today on my own, thanks for boosting my confidence.
Bhaiya i have been following you for last two months and i could see growth in my problem solving ability. Thankyou so much for providing us with the intuitiveness to solve the questions.
If possible then please cover the leetcode and codechef contests as well.
Finally you are back sir!! Please cover leetcode contests problems!!
Sir kal ke potd ki ek video solution bana dena.
wo infosys ke interview me poochaa gaya tha
Mik bhaiya is back finally ❤❤
Wait a lot for your Video ❤❤
same
we need yesterday 's solution by you only ❤❤
Yes coming tomorrow for full details and many things to learn ❤️🙏
Yes coming tomorrow with full details and extra things to learn ❤️🙏
return of the king
MIK is back 😍
Thanks for the clear explanation
GOAT 🐐 Is back ❤
Saal m kitne din ghumte ho mik bhai
Bhaiya is back ❤❤
Great Video
Bhiya codeforces contest ka solution discuss Kiya kro please aap chijo ko acha explain krte hai 🙏
Sir, your code of minimum_no_of_swaps function used in this code fails for one testcase in gfg problem: minimum no. of swaps to sort an array at last 1111th test case, could you please tell why it happen because it works correctly for leetcode, It would be very helpful sir
I am solving questions, working hard..still I am only facing rejections..either my code doesn't run or ques becomes too tricky.... my luck doesn't play well...I am very demotivated.
Sir, joh 2 din ka upload karna hai voh wale videos kab tak aayenge?
MIK Bhaiya, last 2 Days ki POTD ki video kab ayegi? 🥺🥺
bhaiya no of swap dekhne ke liye kyu na ham given array ko sorted array se compare kr le like jis index pe number different honge us samay count++ kar denge and at last count/2 kar denge kyuki jis number se swap hua usme bhi to count++ hoga so is type se number of swap nikal jyega !!
I used BFS + Cyclic Sort to solve this
Here's my Solution:
class Solution {
public:
int minSwapsToSort(vector& arr) {
int n = arr.size();
vector arrWithIndex(n);
// Pair array elements with their indices
for (int i = 0; i < n; i++) {
arrWithIndex[i] = {arr[i], i};
}
// Sort the array by element values
sort(arrWithIndex.begin(), arrWithIndex.end());
vector visited(n, false); // To keep track of visited elements
int swaps = 0;
for (int i = 0; i < n; i++) {
// If already visited or in the correct position, skip
if (visited[i] || arrWithIndex[i].second == i) {
continue;
}
// Count the size of the cycle
int cycleSize = 0;
int current = i;
while (!visited[current]) {
visited[current] = true;
current = arrWithIndex[current]
.second; // Move to the next index in the cycle
cycleSize++;
}
// If there is a cycle of size > 1, it contributes (size - 1) swaps
if (cycleSize > 1) {
swaps += (cycleSize - 1);
}
}
return swaps;
}
int minimumOperations(TreeNode* root) {
// At Same Level, so we'll go with BFS
queue q;
q.push(root);
int ans = 0;
while (!q.empty()) {
int size = q.size();
vector treeNodeVals;
for (int i = 0; i < size; i++) {
TreeNode* temp = q.front();
q.pop();
if (temp->left != NULL) {
treeNodeVals.push_back(temp->left->val);
q.push(temp->left);
}
if (temp->right != NULL) {
treeNodeVals.push_back(temp->right->val);
q.push(temp->right);
}
}
ans += minSwapsToSort(treeNodeVals);
}
return ans;
}
};
@@anonymoushackerar7507 This actually works for GFG Problem: Minimum Swaps to Sort Array.
We missed you
Bhaii please kl wala problem ka solution bna do
Apna aadat lga diye ho bhaiii or kl solution nhi aaya 😢
sahi bola😂, ab kisi aur se smjhn ka man nhi krta
if time please leetcode contest.... dp on last sunday problem
how is storing in map and comparing with the sorted vector is making sure that the swaps are minimum??
ham 2nd type wala bfs kb lagate hai ? koi video hai aapki jismai specifically apne ye bataya ho?
when we use first one and when we use 2nd one BFS
aur agar ham hamesha size wala BFS use kre to galti hogi kya?
thanks
SIR PLEASE SOLVE 21 DEC AND 22 DEC Problem of the day as you skipped these problems on that day @codestorywithMIK
Last two days ke hard questions banao plz
Bro weekly contests ka atleast 3rd question ek kara do plz for every week
Hi MIK, the function of "Minimum Swaps to sort" doesn't work and gives wrong answer on GFG site on the last test case. could you please let me know why?
yes, i also facing the same problem.
Bhaia maine abhi dsa seekhna start hi kara hain. please aap muje bata do ki main apke channel ka use kaise karun effeciently. main pahle ek topic ka theory dekh lu fir usi topic ki jo playlist apne banyi hain usme se questions karuun. Please thoda detail main samja do maine apka chaneel 1 week pahle hi discover kara hain itni saari vedios hain har playlist main mujhe dekh kar samaj nahi aa raha haiin kaise padhu unse
First see this. It will help you get started -
th-cam.com/video/2Jshfog1ETg/w-d-xo.htmlsi=VWnPD-3-tjfcttT1
Ish BFS ka concept konsa video mein hain????
aise to kai videos me bataya hai sir ne is BFS waali cheez ko but latest ek video aai thi sir ki "Reverse Odd Levels of Binary Tree" - Leetcode-2415 usme bataya tha fir se .
@gui-codes thanks for ur information bro but BFS ka koi playlist hain kya???
@@Your_Sandy07 Graph playlist me hain
bhaiya ye sb to bn jata h, please thoda contests k b questions dekheye na, audience for that will be large too ! and we need it. please. the question MAXIMIZE AMOUNT AFTER TWO DAYS OF CONVERSION had me long to think and likewise.
sir this is how i solved this question ...
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int minSwaps(vector& arr){
int n = arr.size();
vectornums;
for(int i=0;ileft){
pq.push(temp->left);
}
if(temp->right){
pq.push(temp->right);
}
}
result += minSwaps(arr);
}
return result;
}
};
Well done. Clean code 👍🏻
But but but what if àrray contain duplicate value 😅.
If It has better time complexity than n*n . Plz tell me😊
bhaiya kal aur purso ka potd upload kar samjh me nhi aaya
Coming tomorrow with details ❤️
Bhaiya mene ye code khud se likha h or jab dry run kia tha to ye code 3ino test cases k liye pass ho rha tha pr jab editor pr run kia to ye ek b test cases pass ni kr pa rha . Kya ap bta sakte h is question ko ese kyu ni kr sakte
Code -->
int minimumOperations(TreeNode* root) {
int count = 0;
queue que;
que.push(root);
while (!que.empty()) {
int n = que.size();
vector vec;
while (n--) {
auto curr = que.front();
que.pop();
vec.push_back(curr);
if (curr->left != NULL) {
que.push(curr->left);
}
if (curr->right != NULL) {
que.push(curr->right);
}
}
int l = 0;
int r = vec.size() - 1;
while (l < r) {
if (vec[l]->val > vec[r]->val) {
auto temp = vec[l]->val;
vec[l]->val = vec[r]->val;
vec[r]->val = temp;
l++;
count++;
} else {
r--;
}
}
}
return count;
}
can you share which test case is failing ?
int solve(vector &v){
int swaps=0,n=v.size();
vectortemp=v;
sort(begin(temp),end(temp));
unordered_mapmp;
for(int i=0;ileft);
if(it->right) q.push(it->right);
}
ans+=solve(v);
}
return ans;
}
my solution. important cheez thi min swaps to get array sorted jo wo decode kr liya smjho question ho gya.. or yahi maine codeforces pe solve kri thi..
Hello bhaiya kaise ho aap,
Bhaiya mujhse ek help chahiye thi aapse plz 🙏 meyne bahut try Kiya but kahi nhi hua, bhaiya final year ke liye project banana hai to uske liye pahle guide registration karna hai and mujhse koi nahi mil rha hai, requirement for guide is ( btech + 5 year experience in job / teaching). Bhaiya aap kisi ko bologe ya phir aapke contact mey koi hoto plz contact kardo, college mey jab tak guide registration nahi karunga tab tak aage proceed nhi kar sakta, bas formality karna hai bhaiya only guide ka details submit karna hai bas itna plz bhaiya help me 🙏🙏🙏🙏
You are really good 🫡