Sort the Matrix Diagonally - (MICROSOFT) : Explanation ➕ Live Coding 🧑🏻‍💻👩🏻‍💻

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 44

  • @password47403
    @password47403 Рік тому +6

    I can't stop commenting on your videos...itne mast hai!
    I'm halfway through the video and already loved the approach and the trick you gave for diagonals.
    Simply awesome!

    • @codestorywithMIK
      @codestorywithMIK  Рік тому

      Thank you so much 😀
      I am so glad to read lovely comments ❤️🙏😇❤️

  • @sumatheultimategirl7477
    @sumatheultimategirl7477 7 днів тому +1

    Thank you so much for bringing this much content for free 😊😊😊

  • @ashwin_anand_dev
    @ashwin_anand_dev 7 днів тому

    Just noticed while studying that your subs increased to 80000 plus. Congratulations bhaiya!
    More power to you!

  • @Augustin_17-i2k
    @Augustin_17-i2k Рік тому +3

    your explaning with neat representation bhaiya❤

  • @dhairyachauhan6622
    @dhairyachauhan6622 Рік тому +2

    WOW!! i have done almost 380 problems on lc and i had never done a problem like this before. I am a bit sad about the fact that i couldn't solve it on my own coz i was trying a way to traverse the matrix diagonally. Anyways thanks bhai as always i learned something new today. :)

    • @codestorywithMIK
      @codestorywithMIK  Рік тому

      Dont feel sad.
      I am glad we learned something new. 🙏❤️😇

    • @ankitkr4119
      @ankitkr4119 9 місяців тому

      kaha job laga bhai abhi ?

  • @leoved1073
    @leoved1073 2 роки тому +1

    Great explaination bro really appreciate it ❣️

  • @Aman-er2yr
    @Aman-er2yr 2 роки тому +1

    Thank you for such an excellent explanation.

  • @OnlyAyushAgarwal
    @OnlyAyushAgarwal 2 роки тому +2

    Nice vro keep going....

  • @priyanshusrivastava2145
    @priyanshusrivastava2145 2 роки тому +1

    great explanation!

  • @rdrahuldhiman19
    @rdrahuldhiman19 11 місяців тому +1

    Hey CoderStoryWithMik, I've a query. But first, thank you so much for your effort, it's helping a lot of people including me.
    Query: what's the difference between [i-j] and [j-i]. As per my understanding it's helping us to identify diagonals and save diagonal values.
    I'm able to get the same answer with both the approaches, both i-j and j-i are working fine.

    • @codestorywithMIK
      @codestorywithMIK  10 місяців тому

      Yes both will work. Because [i-j] or [j-i] will be constant

  • @tanujasharma1262
    @tanujasharma1262 5 місяців тому

    Thankyou so muchhhh❤

  • @fashionvella730
    @fashionvella730 Рік тому +1

    Did it using O(n) space
    class Solution {
    public:
    vector diagonalSort(vector& mat) {
    int n = mat[0].size();
    int l=0;
    for(int k=0;k

  • @password47403
    @password47403 Рік тому +2

    Java implementation using LinkedList:
    class Solution {
    public int[][] diagonalSort(int[][] nums) {
    //top-left to bottom-right: [i - j] technique
    int n = nums.length, m = nums[0].length;
    Map map = new HashMap();
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
    int key = i - j;
    if (map.containsKey(key)) {
    LinkedList list = map.get(key);
    list.addLast(nums[i][j]);
    } else {
    LinkedList list = new LinkedList();
    list.addLast(nums[i][j]);
    map.put(key, list);
    }
    }
    }
    for (LinkedList list : map.values()) {
    Collections.sort(list);
    }
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
    int key = i - j;
    LinkedList list = map.get(key);
    nums[i][j] = list.removeFirst();
    }
    }
    return nums;
    }
    }

  • @M.m554
    @M.m554 Рік тому

    What is the time complexity ?

  • @subhamjha8477
    @subhamjha8477 4 місяці тому

    thanks!

  • @ankitkr4119
    @ankitkr4119 9 місяців тому

    nice

  • @sidharthdhiman4522
    @sidharthdhiman4522 Рік тому +1

    awesome explanation , gonna complete all the videos 🔥🫡

  • @bhuppidhamii
    @bhuppidhamii Рік тому +1

    link of array playlist?

    • @codestorywithMIK
      @codestorywithMIK  Рік тому +1

      Sure.
      ua-cam.com/play/PLpIkg8OmuX-K6A0sEPFxOSJh4_AjCGAFf.html&si=dd2Ha31O5Ey-VdXI
      Thank you for watching 😇❤️

  • @honey6567
    @honey6567 Рік тому +1

    best

  • @Music-tp8gg
    @Music-tp8gg Рік тому

    kuch jada hi acha samjha dete ho bhai

  • @PushpendraKushvaha
    @PushpendraKushvaha 7 місяців тому

    This is my solution after understanding the logic from the video and it pass all the test case on LC.
    private static int[][] diagonalSort(int[][] mat) {
    int n = mat.length;
    int m = mat[0].length;
    Map map = new HashMap();
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
    int d = i - j;
    if (!map.containsKey(d))
    map.put(d, new ArrayList());
    map.get(d).add(mat[i][j]);
    }
    }
    for (Map.Entry ma : map.entrySet()) {
    ma.getValue().sort(Comparator.naturalOrder());
    }
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
    int d = i - j;
    mat[i][j] = map.get(d).removeFirst();
    }
    }
    return mat;
    }

  • @immrhrr
    @immrhrr 5 місяців тому

    i+j, i-j✅

  • @rajeshkumar-ws5ku
    @rajeshkumar-ws5ku 4 місяці тому +2

    nothing to say bhaiya .

  • @pradipsah9900
    @pradipsah9900 Рік тому +3

    bhaiya, doubts hai hh nahi toh comments kya kare😂😂

  • @legendcreatz9783
    @legendcreatz9783 Рік тому +2

    < -----------------------------------JAVA----------------------------------------->
    class Solution {
    public int[][] diagonalSort(int[][] mat) {
    Mapmap = new HashMap();
    for(int i=0;i

  • @nitkarshchourasia2406
    @nitkarshchourasia2406 3 місяці тому

    I can't stop commenting on your videos...itne mast hai!
    I'm halfway through the video and already loved the approach and the trick you gave for diagonals.
    Simply awesome!

  • @nitkarshchourasia2406
    @nitkarshchourasia2406 3 місяці тому

    WOW!! i have done almost 380 problems on lc and i had never done a problem like this before. I am a bit sad about the fact that i couldn't solve it on my own coz i was trying a way to traverse the matrix diagonally. Anyways thanks bhai as always i learned something new today. :)