407. Trapping Rain Water II | BFS | Priority Queue

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ม.ค. 2025

ความคิดเห็น • 18

  • @ARYANMITTAL
    @ARYANMITTAL  13 วันที่ผ่านมา +7

    Company Tags on Telegram & Discord Channel Only❤

    • @SatyamYadav04
      @SatyamYadav04 12 วันที่ผ่านมา

      Hii, yesterday's and today i had just saw and written the code , :(

  • @monsuruokuniyi1234
    @monsuruokuniyi1234 12 วันที่ผ่านมา +11

    I did this one the initial way, like an extension of Trapping rain water I. you know with row and column boundaries, but it failed in test case 19. That was when I figured out the issue of the boundary. By this time I have already spent one hour attempting the problem, so I am here for the intuition 😁

  • @instinct1098
    @instinct1098 10 วันที่ผ่านมา

    Mind Boggling!!! Great way to explain intuition....first time I felt this was better than neetcode's explanation

  • @ravindratholuchuru
    @ravindratholuchuru 11 วันที่ผ่านมา

    Thank you so much for this explanation. You have explained it so clearly.

  • @Its_Shubham_Negi
    @Its_Shubham_Negi 12 วันที่ผ่านมา +3

    Back to back hard ❤❤
    Thanks LeetCode

  • @VishalKumar-wl3kf
    @VishalKumar-wl3kf 12 วันที่ผ่านมา +3

    Now i know from where water is leaking

  • @ManishKumar-kw7qe
    @ManishKumar-kw7qe 11 วันที่ผ่านมา

    thanks for mentioning the initial approach
    i have also tried that but failed

  • @vishalbairagi7238
    @vishalbairagi7238 12 วันที่ผ่านมา

    Thank you bhaiya, excellant explanation

  • @ashutoshjha-z6j
    @ashutoshjha-z6j 12 วันที่ผ่านมา +2

    if a cursor or something is there it will be easy to focus, difficult to get where are you pointing to..... thank you

  • @tentx652
    @tentx652 12 วันที่ผ่านมา

    clear explanAtion

  • @TechieClasher
    @TechieClasher 12 วันที่ผ่านมา +2

    well i did the code which aryan mentioned first but it only passed 15 test cases
    class Solution {
    public int trapRainWater(int[][] h) {
    int n = h.length, m = h[0].length;
    int[][] water = new int[n][m];
    for(int i = 0 ; i < n; i++){
    int leftMax = h[i][0], rightMax = h[i][m - 1], left = 0, right = m - 1;
    water[i][0] = 0; water[i][m - 1] = 0;
    while(left < right){
    if(h[i][left] < h[i][right]){
    if(h[i][left] > leftMax){
    leftMax = h[i][left];
    }
    water[i][left] = leftMax - h[i][left];
    left++;
    } else {
    if(h[i][right] > rightMax){
    rightMax = h[i][right];
    }
    water[i][right] = rightMax - h[i][right];
    right--;
    }
    }
    }
    int totalWater = 0;
    for(int i = 0 ; i < m; i++){
    int leftMax = h[0][i], rightMax = h[n - 1][i], left = 0, right = n - 1;
    water[0][i] = 0; water[n - 1][i] = 0;
    while(left < right){
    if(h[left][i] < h[right][i]){
    if(h[left][i] > leftMax){
    leftMax = h[left][i];
    }
    totalWater += Math.min(water[left][i], leftMax - h[left][i]);
    left++;
    } else {
    if(h[right][i] > rightMax){
    rightMax = h[right][i];
    }
    totalWater += Math.min(water[right][i], rightMax - h[right][i]);
    right--;
    }
    }
    }
    return totalWater;
    }
    }

    • @rasanpreetsingh1712
      @rasanpreetsingh1712 12 วันที่ผ่านมา +1

      same with me😅

    • @kartikaggarwal9788
      @kartikaggarwal9788 12 วันที่ผ่านมา +2

      @@rasanpreetsingh1712 same because it doesn't account for globally. It just consider local minimum boundary and not global.

    • @iamnoob7593
      @iamnoob7593 12 วันที่ผ่านมา

      are u competitive coder?

    • @TechieClasher
      @TechieClasher 12 วันที่ผ่านมา

      @@iamnoob7593 naah normal leetcoder who struggles with implementation

  • @italk-gj5kk
    @italk-gj5kk 12 วันที่ผ่านมา

    nderrated explananation