Print Matrix Diagonally (Diagonal order)

  Рет қаралды 110,293

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Print the matrix Diagonally. You have to print the matrix in diagonal order.

Пікірлер: 142
@manishachanda8089
@manishachanda8089 2 ай бұрын
Very nice explanation sir but there is a bug in your code(the condition of the while loop will be i>=0 && j
@Dadwalfamilyadventures
@Dadwalfamilyadventures 7 жыл бұрын
While conditions should be while (i >= 0 && j
@irfanshaik4440
@irfanshaik4440 2 жыл бұрын
Yes bro now working fine all test cases passed 🙌
@BABEENGINEER
@BABEENGINEER 4 жыл бұрын
You're awesome. I love your video explanations!
@SmartProgramming
@SmartProgramming 6 жыл бұрын
very well explained, keep it up, thank you sir 👍👍
@shiyuwang
@shiyuwang 6 жыл бұрын
Thank you so much! This is very clear, this question is my interview question today. I should have watched it earlier.
@existingstars3665
@existingstars3665 3 жыл бұрын
Which campany
@Ak-um1yg
@Ak-um1yg 3 жыл бұрын
bro which company....what are u doing now
@Dadwalfamilyadventures
@Dadwalfamilyadventures 7 жыл бұрын
Good job in explaining well. All your videos are great. Cheers!! Keep the good work
@alute5532
@alute5532 2 жыл бұрын
Finally have landed into the guru of algorithms bless you & namaskaram
@awalktoinfinity665
@awalktoinfinity665 4 жыл бұрын
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
@MrShortReels
@MrShortReels 4 жыл бұрын
Could u write it sir, cause I want today really.
@awalktoinfinity665
@awalktoinfinity665 4 жыл бұрын
@@MrShortReels you are asking whom ?
@MrShortReels
@MrShortReels 4 жыл бұрын
You commentator can u add the missing.. To algorithims
@MrShortReels
@MrShortReels 4 жыл бұрын
Cause I want to convert this to matlab algorithim
@richardtan4844
@richardtan4844 4 жыл бұрын
It does work. I did test it
@k12i
@k12i 5 жыл бұрын
Thank you for walking us the process of how to solve this type of problems, I find it very helpful!
@jingli2168
@jingli2168 5 жыл бұрын
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
@chrismaheshwari4487
@chrismaheshwari4487 8 ай бұрын
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.........??
@t1910j
@t1910j 2 жыл бұрын
I should have watched this video earlier today. I was asked to solve this in my interview today!
@jaishreeram-o9b47
@jaishreeram-o9b47 Жыл бұрын
in java public class ZigZagPrint { public static void zigZagPrint(int m[][], int r, int c) { for (int k = 0; k = 0 && j < c) { System.out.print(m[i][j] + " "); i--; j++; } System.out.println(); } for (int k = 1; k
@kumarkk3592
@kumarkk3592 4 жыл бұрын
Super b teaching.it is very clear
@oddprogrammer7968
@oddprogrammer7968 4 жыл бұрын
In the second while the condition i>=0 is necessary, otherwise it goes out of bounds.☺
@rohitdixit1617
@rohitdixit1617 5 жыл бұрын
Hi Vivekanand. Thanks for the amazing tutorials. Can you please put out a tutorial for matrix reflection?
@meghaharlalka
@meghaharlalka 5 жыл бұрын
love your videos and explanation
@user-youyoki9054
@user-youyoki9054 4 жыл бұрын
I really want to push the LIKE👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻 button ONE MILLION TIMES!! Thank you such a million, MASTER!!
@user-youyoki9054
@user-youyoki9054 4 жыл бұрын
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)
@amitkumarsingh5414
@amitkumarsingh5414 4 жыл бұрын
Is good if you cover rest of the questions that are generally asked in interview... Good Job
@SusanAmberBruce
@SusanAmberBruce 3 жыл бұрын
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
@alphanumeric9380
@alphanumeric9380 Жыл бұрын
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]
@foo.1396
@foo.1396 6 жыл бұрын
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.
@sagarkumar0190
@sagarkumar0190 6 жыл бұрын
Exactly
@ShinobiEngineer
@ShinobiEngineer 6 жыл бұрын
#include int main() { printf("THANK YOU ! ! !"); return 0; }
@AmbikaKumar21
@AmbikaKumar21 7 жыл бұрын
*_Please make the videon on Longest common Subsecuence with coding_*
@rico5146
@rico5146 5 жыл бұрын
By adding condition (i>=0 && j
@PrimeContent01
@PrimeContent01 2 жыл бұрын
yes yes i also figured it out just now, this code is not complete
@mdfarooq8312
@mdfarooq8312 3 жыл бұрын
Sir, this is valid for only m < n
@HeroesOfAesthetics
@HeroesOfAesthetics 4 жыл бұрын
AMAZING VIDEO!!! JUST what I needed my friend, thank you!
@armandobueno1681
@armandobueno1681 4 жыл бұрын
I'm trying to make a tic tac toe game and this helped me so much haha thanks
@juliaevers5129
@juliaevers5129 4 жыл бұрын
How to do inverse -I mean from a vector to get a matrix in reverse order ?
@bhanukiran5089
@bhanukiran5089 3 жыл бұрын
Python code for matrix of size m*n: ---------------------------------------------------------- no_of_dia=m+n-1 for k in range(no_of_dia): for row in range(m): for col in range(n): if row+col==k: print(num_list[row][col],end=' ') print()
@manishpamnani8428
@manishpamnani8428 4 жыл бұрын
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?
@arjunreddy3996
@arjunreddy3996 4 жыл бұрын
This algorithm breaks for non square matrices, for example in a 3 x 1 matrix.
@Dadwalfamilyadventures
@Dadwalfamilyadventures 7 жыл бұрын
As your logic will fails if we have (4, 3) matrix.
@kalpshah9745
@kalpshah9745 5 жыл бұрын
change 1st while(i>=0 && j=0 && j
@LordHoward
@LordHoward 3 жыл бұрын
Hey peeps, this is kinda different but I wrote this piece of code (JAVASCRIPT) that finds the sum of each of the two diagonals in a square matrix, and it worked for me. //square is the name of the 2D array int sum = 0; //sum of first diagonal int sum2 = 0; //sum of second diagonal int x = 0; int y = square.length - 1; while (x < square.length) { sum += square[x][x]; x++; } x = 0; while (y >= 0 && x < square.length) { sum2 += square[x][y]; y--; x++; } //sout sum, sout sum2
@manishkumarsharma86
@manishkumarsharma86 3 жыл бұрын
Great explanation
@angadrajsingh4311
@angadrajsingh4311 4 жыл бұрын
Amazingly helpful sir . Cleared my confused concept thanks a lot sir . Do make more videos like these...
@rohangarg5473
@rohangarg5473 5 жыл бұрын
beautifully explained , thank you
@kedirali2455
@kedirali2455 5 жыл бұрын
The question is will these formulas work for n by n matrix?
@NileshPatil-si7dy
@NileshPatil-si7dy Жыл бұрын
it doesn't working in 3rows and 4 columns matrix.
@dilmurod9820
@dilmurod9820 3 жыл бұрын
Very good thanks man for lesson
@Huduuniih
@Huduuniih 4 жыл бұрын
For this should work for any (n,m), one needs to have additional conditions in the two while loops, as shown below: for k=0:m-1
@MaratGilyazov
@MaratGilyazov 4 жыл бұрын
There is a mistake as well, in the second loop it should be "i = m - 1", instead of "i = m" :)
@momenuddin5693
@momenuddin5693 6 жыл бұрын
Your tutorial very easily to understand Thank You
@jonesbenet8293
@jonesbenet8293 24 күн бұрын
Thank you for your algorithm
@indiansoul9845
@indiansoul9845 2 ай бұрын
thank you sir, this solution is awesome 🙏
@learn-o-land6759
@learn-o-land6759 11 ай бұрын
Thank you. Great explanation
@Ishakgauri
@Ishakgauri 6 ай бұрын
respect for you sir explained so easily
@danielmugisha6708
@danielmugisha6708 2 жыл бұрын
print the counter diagonals like p, p q, f l r, a g m s, b h n t, c i o, d j, e
@SaumyaSharma007
@SaumyaSharma007 Жыл бұрын
Long live Sir..........Thank u so much.
@xiamojq621
@xiamojq621 2 жыл бұрын
Please unload the code for these program
@CursedDarkOracle
@CursedDarkOracle 2 жыл бұрын
THANK YOU MISTAH, I REALLY LIKE YOUR VIDIO
@kowshikparitala2715
@kowshikparitala2715 3 жыл бұрын
while(i>=0 && j
@Michael-tk1wd
@Michael-tk1wd Жыл бұрын
THATS WHY HES THE MVP THE GOOOOAOT
@aremju7435
@aremju7435 2 жыл бұрын
I tried to implement this algorithm --> first loop works perfect. Seccond loop throws ArrayIndexOutOfBoundsException for i = -1 (which isn't possible)
@firasrg6348
@firasrg6348 Жыл бұрын
What If I want to loop from top to bottom??
@DheerajSharma-fs6je
@DheerajSharma-fs6je 22 күн бұрын
hats off !!!!!!
@bamanstech3006
@bamanstech3006 2 жыл бұрын
Thank you. you are awesome..
@henry999z
@henry999z 2 жыл бұрын
tip : watch 1.75 speed
@hari7110
@hari7110 3 ай бұрын
Thank you sir
@jigardoshi2852
@jigardoshi2852 3 жыл бұрын
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 ?
@pythonenthusiast9292
@pythonenthusiast9292 4 жыл бұрын
Thankyou so much Vivek sir
@amanwebtricks9112
@amanwebtricks9112 3 жыл бұрын
Thank you so much sir
@piyushsharma1638
@piyushsharma1638 6 жыл бұрын
clearly understood. thanks.
@gurjotsingh7192
@gurjotsingh7192 3 жыл бұрын
can you help in Write a program to find frequency of user given item in the 3X3 matrix python
@henry999z
@henry999z 2 жыл бұрын
great stuff btw
@dragonslayer5191
@dragonslayer5191 Жыл бұрын
thank u sir
@aashishsingh5868
@aashishsingh5868 4 жыл бұрын
best explanation
@Caliche_666
@Caliche_666 4 жыл бұрын
Clear and concise. Thank you!!!
@karthikkumaresan1091
@karthikkumaresan1091 3 жыл бұрын
the best
@deepthik9500
@deepthik9500 3 жыл бұрын
sir please explain about antidiagonal matrix where 5*3 matrix
@manishpamnani8428
@manishpamnani8428 4 жыл бұрын
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.
@ShinobiEngineer
@ShinobiEngineer 6 жыл бұрын
धन्यवाद
@tapanjeetroy8266
@tapanjeetroy8266 5 жыл бұрын
Thanks for uploading it.. You are doing a great great job.. Please please upload more of such programming questions.. We really need it
@MrShortReels
@MrShortReels 4 жыл бұрын
Sir could you help me I want to find maximum and minimum local of sin wave by using for loop and if statement
@krishnaverma7744
@krishnaverma7744 4 жыл бұрын
Bhai... thanku so much.... Loving watching ur videos...
@mousemouse1818
@mousemouse1818 5 жыл бұрын
Hi Sir, what about [e],[d,j]. means if we come from -1 those diagonal elements are missing
@suodallos
@suodallos 5 жыл бұрын
Thank you very much buddy !!!!!!!! you explained it really well and in a very non confusing manner.
@lauragaleraalfaro8086
@lauragaleraalfaro8086 3 жыл бұрын
Cool, but what If you want it to traverse it in the opposite way?
@Sushil2874
@Sushil2874 4 жыл бұрын
Thank you so much.. This was very helpful Clear and concise..!!
@sushmagudimetla126
@sushmagudimetla126 5 жыл бұрын
Sir can you post a videos related to bigdataanalytics and cloudcomputing
@manishpamnani8428
@manishpamnani8428 4 жыл бұрын
why is k=1 in the second for loop and not k=0 like the first loop?
@kabboghosh1853
@kabboghosh1853 5 жыл бұрын
very well explained ,thank you sir love from bangladesh
@vrushankdoshi7813
@vrushankdoshi7813 6 жыл бұрын
could you please add a video on in-place rotation of matrix (90 degree) ?
@anshumanpraharaj5582
@anshumanpraharaj5582 5 жыл бұрын
Could you please share the time nd space complexity for each algorithm
@birunthamalini8696
@birunthamalini8696 5 жыл бұрын
Kindly share me program for sum of the all diagonals of a matrix
@academydrawing
@academydrawing 6 жыл бұрын
Sir I want class 12 comp practical comp programing
@krashdata
@krashdata 3 жыл бұрын
Thank you so Much , nice explanation.
@chilukabharath4809
@chilukabharath4809 6 жыл бұрын
good job sir, this question was asked in campus interview.
@Ak-um1yg
@Ak-um1yg 3 жыл бұрын
which company man
@BinaryEmyaneh
@BinaryEmyaneh 5 жыл бұрын
Thank you that helped a lot. Just had to add in a small fix on the second portion of the code.
@WILLGYS
@WILLGYS 2 жыл бұрын
Thanks a lot, that really helped.
@hsandeep007
@hsandeep007 4 жыл бұрын
Excellent and thank you so much.
@shankars4281
@shankars4281 4 жыл бұрын
Thanks! Very well explained.
@sweatheart786
@sweatheart786 4 жыл бұрын
Simple and clear, thank you
@ankitgarhewal9916
@ankitgarhewal9916 6 жыл бұрын
sir plz upload a vedio to rotate a matrix k times
@riaganesha
@riaganesha 5 жыл бұрын
Best channel in KZbin!!
@bot74774
@bot74774 5 жыл бұрын
very clear explanation.
@prabhunathtiwary9852
@prabhunathtiwary9852 5 жыл бұрын
Anyone can help me for antidiagonal programming in java or c !
@sairamgourishetty
@sairamgourishetty 4 жыл бұрын
Perfect explanation 👌
@maheshchowdarypydi6192
@maheshchowdarypydi6192 3 жыл бұрын
Superb 👍👍👍
@RaviKumar-vk6ib
@RaviKumar-vk6ib 3 жыл бұрын
excellent!!!
@cheivcheiv756
@cheivcheiv756 3 жыл бұрын
Good job!
@SachinSPatil-jm4ls
@SachinSPatil-jm4ls 6 жыл бұрын
easy to understand tq sir....
Trick for spiral matrix traversal
10:12
Techdose
Рет қаралды 207 М.
Print Matrix in spiral form ( 2-D array)
17:25
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 124 М.
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 57 МЛН
规则,在门里生存,出来~死亡
00:33
落魄的王子
Рет қаралды 26 МЛН
Zig Zag Array (spiral order array)
10:44
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 40 М.
Negative Time is Real, Physicists Confirm. Kind Of.
6:59
Sabine Hossenfelder
Рет қаралды 13 М.
Diagonal Traverse | Live Coding with Explanation | Leetcode - 498
6:56
Algorithms Made Easy
Рет қаралды 43 М.
Leader in an Array (Code / Algorithm)
15:24
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 21 М.
Subset Sum Problem Dynamic programming
28:54
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 66 М.
DIAGONAL TRAVERSE | LEETCODE # 498 | PYTHON SOLUTION
12:57
Cracking FAANG
Рет қаралды 10 М.
Total number of ways to reach to a cell in matrix
8:52
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 24 М.
Diameter of a Binary Tree (Code/ Algorithm)
17:15
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 94 М.