Print Matrix Diagonally (Diagonal order)

Sdílet
Vložit
  • čas přidán 30. 07. 2017
  • Print the matrix Diagonally. You have to print the matrix in diagonal order.

Komentáře • 140

  • @k12i
    @k12i Před 5 lety +7

    Thank you for walking us the process of how to solve this type of problems, I find it very helpful!

  • @Dadwalfamilyadventures
    @Dadwalfamilyadventures Před 6 lety +11

    Good job in explaining well. All your videos are great. Cheers!! Keep the good work

  • @Dadwalfamilyadventures
    @Dadwalfamilyadventures Před 6 lety +12

    While conditions should be while (i >= 0 && j

    • @irfanshaik4440
      @irfanshaik4440 Před 2 lety

      Yes bro now working fine all test cases passed 🙌

  • @SmartProgramming
    @SmartProgramming Před 6 lety +11

    very well explained, keep it up, thank you sir 👍👍

  • @BABEENGINEER
    @BABEENGINEER Před 3 lety +3

    You're awesome. I love your video explanations!

  • @Caliche_666
    @Caliche_666 Před 4 lety +1

    Clear and concise. Thank you!!!

  • @shiyuwang
    @shiyuwang Před 5 lety +15

    Thank you so much! This is very clear, this question is my interview question today. I should have watched it earlier.

  • @HeroesOfAesthetics
    @HeroesOfAesthetics Před 4 lety

    AMAZING VIDEO!!! JUST what I needed my friend, thank you!

  • @suodallos
    @suodallos Před 4 lety

    Thank you very much buddy !!!!!!!! you explained it really well and in a very non confusing manner.

  • @BinaryEmyaneh
    @BinaryEmyaneh Před 5 lety

    Thank you that helped a lot. Just had to add in a small fix on the second portion of the code.

  • @tapanjeetroy8266
    @tapanjeetroy8266 Před 5 lety

    Thanks for uploading it.. You are doing a great great job.. Please please upload more of such programming questions.. We really need it

  • @Sushil2874
    @Sushil2874 Před 4 lety

    Thank you so much.. This was very helpful
    Clear and concise..!!

  • @angadrajsingh4311
    @angadrajsingh4311 Před 4 lety +1

    Amazingly helpful sir . Cleared my confused concept thanks a lot sir . Do make more videos like these...

  • @momenuddin5693
    @momenuddin5693 Před 6 lety +2

    Your tutorial very easily to understand
    Thank You

  • @henry999z
    @henry999z Před 2 lety

    great stuff btw

  • @vrushankdoshi7813
    @vrushankdoshi7813 Před 6 lety

    could you please add a video on in-place rotation of matrix (90 degree) ?

  • @manishpamnani8428
    @manishpamnani8428 Před 4 lety

    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?

  • @jacktrainer4387
    @jacktrainer4387 Před 4 lety

    Magnificent!

  • @manishpamnani8428
    @manishpamnani8428 Před 4 lety

    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.

  • @meghaharlalka
    @meghaharlalka Před 5 lety

    love your videos and explanation

  • @sweatheart786
    @sweatheart786 Před 3 lety

    Simple and clear, thank you

  • @shankars4281
    @shankars4281 Před 3 lety

    Thanks! Very well explained.

  • @juliaevers5129
    @juliaevers5129 Před 3 lety

    How to do inverse -I mean from a vector to get a matrix in reverse order ?

  • @WILLGYS
    @WILLGYS Před 2 lety

    Thanks a lot, that really helped.

  • @riaganesha
    @riaganesha Před 4 lety

    Best channel in CZcams!!

  • @amitkumarsingh5414
    @amitkumarsingh5414 Před 4 lety

    Is good if you cover rest of the questions that are generally asked in interview... Good Job

  • @rohitdixit1617
    @rohitdixit1617 Před 5 lety +3

    Hi Vivekanand. Thanks for the amazing tutorials. Can you please put out a tutorial for matrix reflection?

  • @armandobueno1681
    @armandobueno1681 Před 3 lety

    I'm trying to make a tic tac toe game and this helped me so much haha thanks

  • @t1910j
    @t1910j Před 2 lety

    I should have watched this video earlier today. I was asked to solve this in my interview today!

  • @learn-o-land6759
    @learn-o-land6759 Před 9 měsíci

    Thank you. Great explanation

  • @user-youyoki9054
    @user-youyoki9054 Před 4 lety +2

    I really want to push the LIKE👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻 button ONE MILLION TIMES!!
    Thank you such a million, MASTER!!

    • @user-youyoki9054
      @user-youyoki9054 Před 4 lety +1

      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)

  • @kedirali2455
    @kedirali2455 Před 5 lety +1

    The question is will these formulas work for n by n matrix?

  • @krishnaverma7744
    @krishnaverma7744 Před 4 lety

    Bhai... thanku so much....
    Loving watching ur videos...

  • @rohangarg5473
    @rohangarg5473 Před 4 lety

    beautifully explained , thank you

  • @jigardoshi2852
    @jigardoshi2852 Před 3 lety

    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 ?

  • @jingli2168
    @jingli2168 Před 5 lety +4

    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

  • @hsandeep007
    @hsandeep007 Před 4 lety

    Excellent and thank you so much.

  • @cheivcheiv756
    @cheivcheiv756 Před 3 lety

    Good job!

  • @kabboghosh1853
    @kabboghosh1853 Před 5 lety

    very well explained ,thank you sir
    love from bangladesh

  • @AmbikaKumar21
    @AmbikaKumar21 Před 6 lety +3

    *_Please make the videon on Longest common Subsecuence with coding_*

  • @anshumanpraharaj5582
    @anshumanpraharaj5582 Před 5 lety

    Could you please share the time nd space complexity for each algorithm

  • @manishpamnani8428
    @manishpamnani8428 Před 4 lety

    why is k=1 in the second for loop and not k=0 like the first loop?

  • @alute5532
    @alute5532 Před 2 lety

    Finally have landed into the guru of algorithms bless you & namaskaram

  • @aminekhelifi837
    @aminekhelifi837 Před 4 lety

    Thank you!

  • @rico5146
    @rico5146 Před 4 lety +2

    By adding condition (i>=0 && j

    • @PrimeContent01
      @PrimeContent01 Před 2 lety

      yes yes i also figured it out just now, this code is not complete

  • @krashdata
    @krashdata Před 3 lety

    Thank you so Much , nice explanation.

  • @oddprogrammer7968
    @oddprogrammer7968 Před 4 lety +3

    In the second while the condition i>=0 is necessary, otherwise it goes out of bounds.☺

  • @mousemouse1818
    @mousemouse1818 Před 5 lety

    Hi Sir, what about [e],[d,j]. means if we come from -1 those diagonal elements are missing

  • @indiansoul9845
    @indiansoul9845 Před 12 dny

    thank you sir, this solution is awesome 🙏

  • @Ishakgauri
    @Ishakgauri Před 4 měsíci

    respect for you sir explained so easily

  • @piyushsharma1638
    @piyushsharma1638 Před 6 lety

    clearly understood. thanks.

  • @dilmurod9820
    @dilmurod9820 Před 3 lety

    Very good thanks man for lesson

  • @lauragaleraalfaro8086
    @lauragaleraalfaro8086 Před 3 lety

    Cool, but what If you want it to traverse it in the opposite way?

  • @sairamgourishetty
    @sairamgourishetty Před 4 lety

    Perfect explanation 👌

  • @manishachanda8089
    @manishachanda8089 Před 5 dny

    Very nice explanation sir but there is a bug in your code(the condition of the while loop will be i>=0 && j

  • @CursedDarkOracle
    @CursedDarkOracle Před 2 lety

    THANK YOU MISTAH, I REALLY LIKE YOUR VIDIO

  • @bamanstech3006
    @bamanstech3006 Před 2 lety

    Thank you. you are awesome..

  • @foo.1396
    @foo.1396 Před 6 lety +1

    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.

  • @RaviKumar-vk6ib
    @RaviKumar-vk6ib Před 2 lety

    excellent!!!

  • @ixt2010
    @ixt2010 Před 5 lety

    Very Well explained.

  • @maheshchowdarypydi6192

    Superb 👍👍👍

  • @MrShortReels
    @MrShortReels Před 4 lety

    Sir could you help me I want to find maximum and minimum local of sin wave by using for loop and if statement

  • @firasrg6348
    @firasrg6348 Před rokem

    What If I want to loop from top to bottom??

  • @chilukabharath4809
    @chilukabharath4809 Před 5 lety +1

    good job sir,
    this question was asked in campus interview.

  • @aremju7435
    @aremju7435 Před 2 lety

    I tried to implement this algorithm --> first loop works perfect. Seccond loop throws ArrayIndexOutOfBoundsException for i = -1 (which isn't possible)

  • @bot74774
    @bot74774 Před 4 lety

    very clear explanation.

  • @manishkumarsharma86
    @manishkumarsharma86 Před 3 lety

    Great explanation

  • @Vishal-nc8ju
    @Vishal-nc8ju Před 5 lety +1

    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

  • @prabhunathtiwary9852
    @prabhunathtiwary9852 Před 5 lety

    Anyone can help me for antidiagonal programming in java or c !

  • @dheerajverma8999
    @dheerajverma8999 Před 7 lety

    great sir

  • @SusanAmberBruce
    @SusanAmberBruce Před 3 lety +2

    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 Před rokem

      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]

  • @gurjotsingh7192
    @gurjotsingh7192 Před 3 lety

    can you help in Write a program to find frequency of user given item in the 3X3
    matrix python

  • @manishpamnani8428
    @manishpamnani8428 Před 4 lety

    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?

  • @sushmagudimetla126
    @sushmagudimetla126 Před 5 lety

    Sir can you post a videos related to bigdataanalytics and cloudcomputing

  • @SS-id4gp
    @SS-id4gp Před 4 lety

    This is lit 🤟

  • @SachinSPatil-jm4ls
    @SachinSPatil-jm4ls Před 6 lety

    easy to understand tq sir....

  • @SaumyaSharma007
    @SaumyaSharma007 Před rokem

    Long live Sir..........Thank u so much.

  • @chrismaheshwari4487
    @chrismaheshwari4487 Před 5 měsíci

    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.........??

  • @PrinceKumar-eb8hd
    @PrinceKumar-eb8hd Před 6 lety

    very nice video

  • @kumarkk3592
    @kumarkk3592 Před 4 lety

    Super b teaching.it is very clear

  • @karthikkumaresan1091
    @karthikkumaresan1091 Před 3 lety

    the best

  • @pythonenthusiast9292
    @pythonenthusiast9292 Před 3 lety

    Thankyou so much Vivek sir

  • @aashishsingh5868
    @aashishsingh5868 Před 4 lety

    best explanation

  • @arjunreddy3996
    @arjunreddy3996 Před 3 lety +1

    This algorithm breaks for non square matrices, for example in a 3 x 1 matrix.

  • @awalktoinfinity665
    @awalktoinfinity665 Před 4 lety +8

    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

  • @mdfarooq8312
    @mdfarooq8312 Před 3 lety

    Sir, this is valid for only m < n

  • @amanwebtricks9112
    @amanwebtricks9112 Před 2 lety

    Thank you so much sir

  • @deepakbhargav9633
    @deepakbhargav9633 Před 5 lety

    Thank you SIR

  • @ShinobiEngineer
    @ShinobiEngineer Před 6 lety +2

    धन्यवाद

  • @Michael-tk1wd
    @Michael-tk1wd Před rokem

    THATS WHY HES THE MVP THE GOOOOAOT

  • @birunthamalini8696
    @birunthamalini8696 Před 5 lety

    Kindly share me program for sum of the all diagonals of a matrix

  • @academydrawing
    @academydrawing Před 6 lety

    Sir I want class 12 comp practical comp programing

  • @deepthik9500
    @deepthik9500 Před 3 lety

    sir please explain about antidiagonal matrix where 5*3 matrix

  • @ankitgarhewal9916
    @ankitgarhewal9916 Před 6 lety

    sir plz upload a vedio to rotate a matrix k times

  • @alejandroreyesmorales5257

    some one, can do in a reverse way?

    • @ColdFlamedFox
      @ColdFlamedFox Před 4 lety

      I had to do it reversed and I did according to this method. I assume it's a bit too late now though?

  • @hari7110
    @hari7110 Před 20 dny

    Thank you sir

  • @dragonslayer5191
    @dragonslayer5191 Před rokem

    thank u sir

  • @matiasmunoz7063
    @matiasmunoz7063 Před 2 lety

    TE AMO WN TE AMO

  • @NileshPatil-si7dy
    @NileshPatil-si7dy Před rokem

    it doesn't working in 3rows and 4 columns matrix.

  • @Dadwalfamilyadventures
    @Dadwalfamilyadventures Před 6 lety +3

    As your logic will fails if we have (4, 3) matrix.