Very Well Explained Sir. SImple Explanation and Nice Illustration. I always refer to this video when i am stuck on Algorithms. THank You Sir Once Again.
void MakeDiagonalArray(int ** ar, int n1, int n2) { int i, j; int k, num = 1; /* The variable 'k' - trace through every starting of the diagonals The variable 'i', 'j' - go on incrementing i by +1 - go on decrementing j by -1 The variable 'num' - 각 배열에 자연수를 대입. */ // Tracking first elements of the columns for (k = 0; k < n2; k++) { i = 0; j = k; while (j > -1 && i < n1) { /* Each diagonal ends at the first column or the last row. */ ar[i][j] = num++; i++; j--; }// while (j > -1 || i < n1) }// for (k = 0; k < n2; k++)
// Tracking last elements of the rows for (k = 1; k < n1; k++) { i = k; j = n2 - 1; while (j > -1 && i < n1) { /* Each diagonal ends at the first column or the last row. */ ar[i][j] = num++; i++; j--; }// while (j > -1 && i < n1) }// for (k = 1; k < n1; k++) }// void MakeDiagonalArray(int ** ar, int n1, int n2)
I approached this as bfs of binary tree wherein on current element[0,0], insert bottom[1,0] and right element[0,1] in queue. would that approach work ?
Thanks for ur video. However, there is a bug in your nested while loop. consider a 4 by 2 matrix. Correct answer I think should be def dia_print(arr): output = [] for i in range(arr.shape[0]): j = 0 while i >= 0 and j
I suppose the conditions of both while loops should be combined otherwise the program fails for 3x2 Matrix as it would eventually try to look for element(0,2) which is not present.
The same program in python 3, thanks for your help. # python 3x example # diagonal iteration of array m x n. matrix = [ ['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h', 'i', 'j'], ['k', 'l', 'm', 'n', 'o'], ['p', 'q', 'r', 's', 't'] ] m = 4 # rows n = 5 # columns
for k in range(0, m): i=k j=0 while i >= 0: print(matrix[i][j], end = "") i = i-1 j = j+1 print() for k in range(1, n): i = m-1 j = k while j
hi sir ! actually in both while ..you missed one more condition i.e., to ensure to i and j both to remain within boundaries of matrix .. in the first while for printing the row side diagonal you should put a condition so that j should be within "n" . for ex take matrix of size 5*2 . check this program will not work and will throw array index out of bound exception . similarly for second while in the second for loop , put a condition for i>=0 . anyways great video
Thank you for walking us the process of how to solve this type of problems, I find it very helpful!
Good job in explaining well. All your videos are great. Cheers!! Keep the good work
While conditions should be while (i >= 0 && j
Yes bro now working fine all test cases passed 🙌
very well explained, keep it up, thank you sir 👍👍
You're awesome. I love your video explanations!
Clear and concise. Thank you!!!
Thank you so much! This is very clear, this question is my interview question today. I should have watched it earlier.
Which campany
bro which company....what are u doing now
AMAZING VIDEO!!! JUST what I needed my friend, thank you!
Thank you very much buddy !!!!!!!! you explained it really well and in a very non confusing manner.
Thank you that helped a lot. Just had to add in a small fix on the second portion of the code.
Thanks for uploading it.. You are doing a great great job.. Please please upload more of such programming questions.. We really need it
Thank you so much.. This was very helpful
Clear and concise..!!
Amazingly helpful sir . Cleared my confused concept thanks a lot sir . Do make more videos like these...
Your tutorial very easily to understand
Thank You
great stuff btw
could you please add a video on in-place rotation of matrix (90 degree) ?
how to check if there is a next element or not?
Like in the matrix above we don't have a element after 22, how do we determine that?
Magnificent!
Very Well Explained Sir. SImple Explanation and Nice Illustration. I always refer to this video when i am stuck on Algorithms.
THank You Sir Once Again.
love your videos and explanation
Simple and clear, thank you
Thanks! Very well explained.
How to do inverse -I mean from a vector to get a matrix in reverse order ?
Thanks a lot, that really helped.
Best channel in CZcams!!
Is good if you cover rest of the questions that are generally asked in interview... Good Job
Hi Vivekanand. Thanks for the amazing tutorials. Can you please put out a tutorial for matrix reflection?
I'm trying to make a tic tac toe game and this helped me so much haha thanks
I should have watched this video earlier today. I was asked to solve this in my interview today!
Thank you. Great explanation
I really want to push the LIKE👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻 button ONE MILLION TIMES!!
Thank you such a million, MASTER!!
void MakeDiagonalArray(int ** ar, int n1, int n2) {
int i, j;
int k, num = 1;
/*
The variable 'k'
- trace through every starting of the diagonals
The variable 'i', 'j'
- go on incrementing i by +1
- go on decrementing j by -1
The variable 'num'
- 각 배열에 자연수를 대입.
*/
// Tracking first elements of the columns
for (k = 0; k < n2; k++) {
i = 0;
j = k;
while (j > -1 && i < n1) {
/*
Each diagonal ends at the first column
or the last row.
*/
ar[i][j] = num++;
i++;
j--;
}// while (j > -1 || i < n1)
}// for (k = 0; k < n2; k++)
// Tracking last elements of the rows
for (k = 1; k < n1; k++) {
i = k;
j = n2 - 1;
while (j > -1 && i < n1) {
/*
Each diagonal ends at the first column
or the last row.
*/
ar[i][j] = num++;
i++;
j--;
}// while (j > -1 && i < n1)
}// for (k = 1; k < n1; k++)
}// void MakeDiagonalArray(int ** ar, int n1, int n2)
The question is will these formulas work for n by n matrix?
Bhai... thanku so much....
Loving watching ur videos...
beautifully explained , thank you
I approached this as bfs of binary tree wherein on current element[0,0], insert bottom[1,0] and right element[0,1] in queue. would that approach work ?
Thanks for ur video. However, there is a bug in your nested while loop.
consider a 4 by 2 matrix. Correct answer I think should be
def dia_print(arr):
output = []
for i in range(arr.shape[0]):
j = 0
while i >= 0 and j
Excellent and thank you so much.
Good job!
very well explained ,thank you sir
love from bangladesh
*_Please make the videon on Longest common Subsecuence with coding_*
Could you please share the time nd space complexity for each algorithm
why is k=1 in the second for loop and not k=0 like the first loop?
Finally have landed into the guru of algorithms bless you & namaskaram
Thank you!
By adding condition (i>=0 && j
yes yes i also figured it out just now, this code is not complete
Thank you so Much , nice explanation.
In the second while the condition i>=0 is necessary, otherwise it goes out of bounds.☺
Hi Sir, what about [e],[d,j]. means if we come from -1 those diagonal elements are missing
thank you sir, this solution is awesome 🙏
respect for you sir explained so easily
clearly understood. thanks.
Very good thanks man for lesson
Cool, but what If you want it to traverse it in the opposite way?
Perfect explanation 👌
Very nice explanation sir but there is a bug in your code(the condition of the while loop will be i>=0 && j
THANK YOU MISTAH, I REALLY LIKE YOUR VIDIO
Thank you. you are awesome..
I suppose the conditions of both while loops should be combined otherwise the program fails for 3x2 Matrix as it would eventually try to look for element(0,2) which is not present.
Exactly
excellent!!!
Very Well explained.
Superb 👍👍👍
Sir could you help me I want to find maximum and minimum local of sin wave by using for loop and if statement
What If I want to loop from top to bottom??
good job sir,
this question was asked in campus interview.
which company man
I tried to implement this algorithm --> first loop works perfect. Seccond loop throws ArrayIndexOutOfBoundsException for i = -1 (which isn't possible)
very clear explanation.
Great explanation
if you are reading this comment then believe me guys this is the best channel to improve your thinking skills.
It helps me a lot. thanku sir
Anyone can help me for antidiagonal programming in java or c !
great sir
The same program in python 3, thanks for your help.
# python 3x example
# diagonal iteration of array m x n.
matrix = [ ['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k', 'l', 'm', 'n', 'o'],
['p', 'q', 'r', 's', 't'] ]
m = 4 # rows
n = 5 # columns
for k in range(0, m):
i=k
j=0
while i >= 0:
print(matrix[i][j], end = "")
i = i-1
j = j+1
print()
for k in range(1, n):
i = m-1
j = k
while j
Is this program for specific element pls help I need diagonal of specific element matrix 3*3 k=6 output=[2,6] and [6,8]
can you help in Write a program to find frequency of user given item in the 3X3
matrix python
At the line i=i-1 inside while loop when we calculate the i it results to -1 , but how can a index be a negative value?
while(i>=0) and while(j
Sir can you post a videos related to bigdataanalytics and cloudcomputing
This is lit 🤟
easy to understand tq sir....
Long live Sir..........Thank u so much.
Can't we use the (i+j) and then compare it to the x variable with the help of IF function in a loop and then increment x.........??
very nice video
Super b teaching.it is very clear
the best
Thankyou so much Vivek sir
best explanation
This algorithm breaks for non square matrices, for example in a 3 x 1 matrix.
hi sir ! actually in both while ..you missed one more condition i.e., to ensure to i and j both to remain within boundaries of matrix .. in the first while for printing the row side diagonal you should put a condition so that j should be within "n" . for ex take matrix of size 5*2 . check this program will not work and will throw array index out of bound exception .
similarly for second while in the second for loop , put a condition for i>=0 .
anyways great video
Could u write it sir, cause I want today really.
@@MrShortReels you are asking whom ?
You commentator can u add the missing.. To algorithims
Cause I want to convert this to matlab algorithim
It does work. I did test it
Sir, this is valid for only m < n
Thank you so much sir
Thank you SIR
धन्यवाद
THATS WHY HES THE MVP THE GOOOOAOT
Kindly share me program for sum of the all diagonals of a matrix
Sir I want class 12 comp practical comp programing
sir please explain about antidiagonal matrix where 5*3 matrix
sir plz upload a vedio to rotate a matrix k times
some one, can do in a reverse way?
I had to do it reversed and I did according to this method. I assume it's a bit too late now though?
Thank you sir
thank u sir
TE AMO WN TE AMO
it doesn't working in 3rows and 4 columns matrix.
As your logic will fails if we have (4, 3) matrix.
change 1st while(i>=0 && j=0 && j