Rotating the Box | Brute Force | Optimal | Leetcode 1861 | codestorywithMIK

  Рет қаралды 4,579

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 42
@jeehub041
@jeehub041 17 сағат бұрын
Jab se aapke videos dekhne lag gaya hu Consistent rahne lag gaya hu Coding me rum gaya hu Logics sab samajh gaya hu ❤❤🎉🎉 You are my real hero , bhaiya 🙌🙌
@shikharai-tl4vb
@shikharai-tl4vb 6 сағат бұрын
mik be like "or bss yaha mai pighal gaya hu "
@codestorywithMIK
@codestorywithMIK 2 сағат бұрын
This means a lot ❤️🙏😇
@DrOnZeR2022
@DrOnZeR2022 21 сағат бұрын
Bhaiya I solved it by myself it similar to the question rotate image towards right first I rotate the image towards right by transpose and then reverse all the rows and then just add the effect of gravity❤
@gui-codes
@gui-codes 21 сағат бұрын
MIK sir, I feel so good I was able to solve this on my own. My problem solving is improving day by day. Thank you so much
@KhushnorRahmanMeem
@KhushnorRahmanMeem 20 сағат бұрын
I never expected to solve it by my own. Bt I did alhamdulillah. Thank you
@thekindspill
@thekindspill 13 сағат бұрын
Thank God I got to know about your channel. I learn everyday from you ❤
@faizanmohammed7687
@faizanmohammed7687 14 сағат бұрын
I solved. Observed that transpose and reversing the array on my own. Then while simulating gravity I took a bit help of chatgpt. not completely. I was doing wrong updations on empty cell (`.`). But later I also got to know that simulating gravity would not really require to do rotation first, I could simply move the # to right. So it's new thing to learn.
@Sarthak2421
@Sarthak2421 14 сағат бұрын
Instead of doing transpose and then reversing it , we can play around the index and it will do the job : int row = box.size(); int col = box[0].size(); vector rotated(col , vector (row)); //for copying elements for(int i = 0 ; i < row ; i++) { for(int j = 0 ; j < col ; j++) { rotated[j][row - i - 1] = box[i][j]; } }
@gamersgame43
@gamersgame43 21 сағат бұрын
finally solved the problem alone after 1hr, then saw video came
@gui-codes
@gui-codes 21 сағат бұрын
Same bhai. I took me more than 1 hour but solved it finally.
@peterfromengland8663
@peterfromengland8663 17 сағат бұрын
​@@gui-codes it took me 19 minutes
@tauheedahmed4073
@tauheedahmed4073 15 сағат бұрын
Me too bhai took 30 min
@indiann871
@indiann871 10 сағат бұрын
@@peterfromengland8663 10 min here
@AmandeepSingh-uq3wp
@AmandeepSingh-uq3wp 11 сағат бұрын
I also thought of same optimized approach and then I thought reversing row does not make any sense and it is just increasing the time expense of solution. So I use the gravity simulation logic first and then apply the transpose logic directly without reversing rows. Code (if someone wants to see the code) : class Solution { public: vector rotateTheBox(vector& box) { int n = box.size(); int m = box[0].size(); for (int i = 0; i < n; i++) { int end = m - 1; for (int start = m - 1; start >= 0; start--) { if (box[i][start] == '*') { end = start - 1; } else if (box[i][start] == '#') { box[i][start] = '.'; box[i][end] = '#'; end--; } } } vector ans(m, vector(n, '.')); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans[j][n - i - 1] = box[i][j]; } } return ans; } };
@ugcwithaddi
@ugcwithaddi 21 сағат бұрын
Was waiting 😊. Thank you for the consistency
@faizanmohammed7687
@faizanmohammed7687 14 сағат бұрын
I really want to start the jan 1 with good news, but I was thinking how. I am simultaneously developing projects and solving problems. I alotted times. If you have some suggestions, can you reccommend ?
@tanishqagarg7582
@tanishqagarg7582 9 сағат бұрын
sir plz make a video what to do as a fresher from 3rd tier cllg . how to make our cv shine within months plz . i get a lot of rejections because my cv nevr gets selected and i think most of us is facing the same issue i trust that u can help us u r genuine thank u for the videos and everything in advance
@codestorywithMIK
@codestorywithMIK Сағат бұрын
Hello there ❤️. I understand how challenging it can be to stand out as a fresher. Your CV is the first step in making an impression, and I will definitely work on creating a detailed video to address this. Meanwhile, focus on adding relevant projects, building a strong LinkedIn profile, and highlighting any internships or certifications. Stay consistent, keep learning, and don’t lose hope
@subasm2160
@subasm2160 16 сағат бұрын
No need to do transpose and reverse for the rotation just use res[j][m-i-1] = input [i][j], m = no of col
@codestorywithMIK
@codestorywithMIK 16 сағат бұрын
Indeed that’s a cleaner way. Good one 🙌♥️
@subasm2160
@subasm2160 16 сағат бұрын
@codestorywithMIK Thanks man 🙌😊
@aws_handles
@aws_handles 11 сағат бұрын
Thanks a lot for details
@jain5184
@jain5184 21 сағат бұрын
mik bhaiya done sir ek news ayega meri or se 1:00
@codestorywithMIK
@codestorywithMIK 21 сағат бұрын
Sure ❤️
@peterfromengland8663
@peterfromengland8663 17 сағат бұрын
Did it on my own 😢 But it seems easy problem
@tutuimam3381
@tutuimam3381 21 сағат бұрын
Amazing ❤
@dhirajmahato6500
@dhirajmahato6500 15 сағат бұрын
Plz upload binary tree concept video bro
@er.jitu4
@er.jitu4 15 сағат бұрын
My Approach 👇 class Solution { public: vector rotateTheBox(vector& box) { int m=box.size(); int n=box[0].size(); for(auto &row:box){ int cntEmpty=0; for(int j=n-1;j>=0;j--){ if(row[j]=='.')cntEmpty++; else if(row[j]=='*')cntEmpty=0; else{ if(cntEmpty==0)continue; row[j+cntEmpty]='#'; row[j]='.'; } } } vectorres; for(int col=0;col=0;row--){ temp.push_back(box[row][col]); } res.push_back(temp); } return res; } };
@rickdutta942
@rickdutta942 16 сағат бұрын
class Solution { public: vector rotateTheBox(vector& box) { int m = box.size(); // rows int n = box[0].size(); // cols vector ans(n, vector(m)); int j = m-1; // start from end column of ans matrix for (auto& row : box) { int r = n - 1; int l = n - 1; //Arrage the stones in each row of the given box for (l; l >= 0; l--) { if (row[l] == '*' || row[l] == '.' && row[r] != '.') r = l; if (row[l] == '#' && row[r] == '.') { swap(row[l], row[r]); r--; } } //First arranged row goes to last ans column int i = 0; for(char &c: row) { ans[i++][j]= c; } j--; } return ans; } }; TC : O(2(m x n)) SC: O(1) excluding output array
@invincibleinvincible3215
@invincibleinvincible3215 6 сағат бұрын
Mene to stack ka use karke isko solve kiya I don't know mene itna kyu socha.
@codestorywithMIK
@codestorywithMIK Сағат бұрын
Nothing wrong in that. Glad to see yet another approach. Feel free to share the approach with others. ❤️
@anupamtiwary4265
@anupamtiwary4265 14 сағат бұрын
//In this I am shifting the stones first then rotating //this is very similar to move zeros to end void moveStones(vector& row) { int n = row.size(); int empty = n - 1; for (int i = n - 1; i >= 0; --i) { if (row[i] == '*') { // move the empty pointer if u get a wall empty = i - 1; } else if (row[i] == '#') { // move stone to the nearest empty spot swap(row[i], row[empty]); empty--; } // do nothing if it's empty space } } vector rotateTheBox(vector& box) { int m = box.size(),n=box[0].size(); for(auto &row : box){ moveStones(row); } vectorans(n,vector(m)); for(int i=0;i
@harshlalawat
@harshlalawat 12 сағат бұрын
Done with only single iteration class Solution { public: vector rotateTheBox(vector& box) { vector ans(box[0].size(), vector(box.size(), '.')); for(int i=box.size()-1; i>=0; --i){ for(int j=box[0].size()-1, count=j; j>=0; --j){ if(box[i][j] == '#') ans[count--][box.size()-i-1] = '#'; else if(box[i][j] == '*') count = j, ans[count--][box.size()-i-1] = '*'; } } return ans; } };
@dayashankarlakhotia4943
@dayashankarlakhotia4943 19 сағат бұрын
public char[][]rotateTheBox(char[][]box){ int m=box.length,n=box[0].lenght; char[][]ans=new char[n][m]; for(int i=0;i=0;--j){ ans[j][m-i-1]='.'; if(box[i][j]!='.'){ k=box[i][j]=='*'?j:k; ans[k--][m-i-1]=box[i][j]; } } return ans; } 🎉❤
@KunalRajput-r2q5m
@KunalRajput-r2q5m 18 сағат бұрын
I exracted each row and did Insertion sort with slight modification and then copied to the resultant matrix. Time Complexity (m * n) public void sort(char[]arr){ for(int i=1;i=0;j--){ if(arr[j]=='*')break; if(arr[j]=='#' && arr[j+1]=='.'){ arr[j+1]='#'; arr[j]='.'; } } }
@dayashankarlakhotia4943
@dayashankarlakhotia4943 21 сағат бұрын
First 🎉❤
@AryanVats603
@AryanVats603 21 сағат бұрын
sir,my solution vector rotateTheBox(vector& box) { int m=box.size(); int n=box[0].size(); vector rotated(n, vector(m)); for(int i=m-1;i>=0;i--){ for(int j=n-1;j>=0;j--){ if(box[i][j]=='#'){ int x=j+1; while(x
@sarthakawasthi5686
@sarthakawasthi5686 19 сағат бұрын
can someone please tell the error in my code !! Logic - Shifting stones to the right and then rotating the box class Solution { public: vector rotateTheBox(vector& box) { int m = box.size(); int n = box[0].size(); for(int i =0;i
@rickdutta942
@rickdutta942 17 сағат бұрын
Hard to understand what are you trying to do. If you can't figure the solution on your own, try taking solution from solution section and before you implement fully understand that code. Don't worry this kind of things happen with everyone.
@sarthakawasthi5686
@sarthakawasthi5686 14 сағат бұрын
@@rickdutta942 i am just shifting the stones to voids untill blockages is encountered and then after everything is done , i m rotating the box/ matrix
@asifulhaquemridul7489
@asifulhaquemridul7489 3 сағат бұрын
I was able to solve this using stack. class Solution: def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]: for i in range(len(box)): stack = [] for j in range(len(box[i])-1, -1, -1): if not stack and box[i][j] == ".": stack.append((i,j)) if stack and box[i][j] == "*": stack.pop() if stack and box[i][j] == "#": pos_i, pos_j = stack.pop() box[pos_i][pos_j] = "#" box[i][j] = "." stack.append((pos_i,pos_j-1)) res = [] for col in range(len(box[0])): new_col = [] for row in range(len(box)-1, -1, -1): new_col.append(box[row][col]) res.append(new_col) return res
Complete Dynamic Programming Practice - Noob to Expert | Topic Stream 1
3:50:43
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 92 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
SOFTWARE DEVELOPMENT & ENGINEERING ( lecture 2 )
1:17:58
IDEAS Project at Cosmopolitan
Рет қаралды 256
C Programming Tutorial for Beginners
3:46:13
freeCodeCamp.org
Рет қаралды 14 МЛН
Quiet Night: Deep Sleep Music with Black Screen - Fall Asleep with Ambient Music
3:05:46
The ACCIDENTAL Success of Jackie Shroff
30:37
Vedant Rusty
Рет қаралды 50 М.
How Many Balloons To Make A Store Fly?
00:22
MrBeast
Рет қаралды 92 МЛН