Spiral Matrix | Leetcode-54 | Amazon, Microsoft, Paytm | Explanation ➕ Live Coding 🧑🏻‍💻👩🏻‍💻

preview_player
Показать описание
Hi everyone, this is the 10th of our Array Playlist.
In this video we will try to solve a very famous and frequently asked 2-D Array Qn “SPIRAL MATRIX”.
We will do live coding after explanation and see if we are able to pass all the test cases.

Problem Name : SPIRAL MATRIX
Company Tags : Paytm, Zoho, Morgan Stanley, Accolite, Amazon, Microsoft,
Snapdeal, D-E-Shaw, MakeMyTrip, Oracle, MAQ Software,
Nearbuy, Nagarro, BrowserStack

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Рекомендации по теме
Комментарии
Автор

Hi Bhaiya! I am following your your videos for past few weeks and the way you are putting all the thoughts and the way you are going about a solution is jus awesome.Thank you for the brilliant content. I have also taken a look of the github repository.Such a good collection of questions. Eagerly waiting for the new videos and graph playlist😊

sarathkumardunga
Автор

*FOR THOSE WHO ARE WONDERING FOR THE FULL SOLUTION WITH NO MISSING PART, HERE IT IS*

class Solution {
public:
vector<int> matrix) {
int m = matrix.size(); // row
if (matrix.empty() || matrix[0].empty()) return {};
int n = matrix[0].size(); // column

int dir = 0;

// dir = 0: left to right;
// dir = 1; top to bottom;
// dir = 2; right to left;
// dir = 3; bottom to top;

int left = 0;
int right = n - 1;
int top = 0;
int bottom = m - 1;
vector<int> result;

while (result.size() < (m * n)) {
if (dir == 0) {
// left to right
// constant: row(top)
for (int i = left; i <= right; i++) {

}
top++;
} else if (dir == 1) {
// top to bottom
// constant: column(right)

for (int i = top; i <= bottom; i++) {

}
right--;
}

else if (dir == 2) {
// right to left
// constant: row(bottom)

for (int i = right; i >= left; i--) {

}
bottom--;
}
else if (dir == 3) {
// bottom to top
// constant : left;

for (int i = bottom; i >= top; i--) {

}
left++;
}
dir = (dir + 1) % 4;
}
return result;
}
};

nitkarshchourasia
Автор

One of those problems where naming the variables meaningfully is very very important, otherwise it would lead to a lot of confusion.

sanjaykatta
Автор

Your explanation is better than striver 🎉

Prakash-xnn
Автор

Ah I found this video in the morning . Masterpiece bro ❣

souravjoshi
Автор

Nice one...
also friendly advice to all the student: after learning the algo try to code yourself without watching sir code.

coldcoke
Автор

i still remember when i watched that video today on a streak of 403 never able to do this without you thanks bro

AnandKumar-kzls
Автор

Bhai aaj tak itne DSA ke video dkh liye particular javascript me code krne k liye wahi video dkha pdta tha
Tumhari video dkh kr smjh kr khud javascript me code likh deta hu
Well explained 🎉

darshandm
Автор

the very very easiest solution i have ever seen for this question. thank you bhaiya, i was stucked in this question for last 3 very helpful

yashpaunikar
Автор

very clear and easy explanation. Thanks.

subhamjha
Автор

what is the condition under while loop ..aapne baad me btane ko bola video me pr apne submit kr dia

insidious_
Автор

Where you defined left, right, top down!
Btw

malavipande
Автор

Such a wonderful explanation, thanks sir

vishal-sret
Автор

again saying i saw the same question from striver stuck in this from the last 1 hour or sooo got it now mannnn

anonymous-qyvw
Автор

Great job :)

BTW For dir you can also simply do a % operator

PakIslam
Автор

bhaiya, spiral matrix 3 ka solution daal do pls samjh nai aa rha kaise solve kare

lakshsinghania
Автор

Hey I think you miss to tell about the breaking condition in while loop? Btw I got it from from your explanation part So no problem at all. Thanks.

vineetkumar
Автор

you have not defined variables top, down, left and right ?

namanjain
Автор

pls sara vdo sb me sc nd tc de do har sol ka

aayushranjan
Автор

started on 8th feb completed till lec 10 @ 3:10 AM .

thanks bhaiya and once again 🤎 if possible plzz accept my meeting request .

shreyash__
visit shbcf.ru