2257. Count Unguarded Cells in the Grid | Simulation | Deep Time Complexity Analysis Problem

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 2024

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

  • @nocodelimits
    @nocodelimits 3 วันที่ผ่านมา +2

    great explanation sirr🔥🔥
    Aryan bhai help me for 21 days to start again to come back on DSA after 6 months of gap do keep consistently posting video I will also continue with you in the same journey

  • @Engineering.Wallah
    @Engineering.Wallah 3 วันที่ผ่านมา

    class Solution {
    public:
    void solve1(vector& grid, vector& vis, int i,
    int j) {
    int m = grid.size(), n = grid[0].size();
    for (int col = j + 1; col < n; col++) {
    if (grid[i][col] != 0)
    break;
    vis[i][col] = 1;
    }
    }
    void solve2(vector& grid, vector& vis, int i,
    int j) {
    int m = grid.size(), n = grid[0].size();
    for (int col = j - 1; col >= 0; col--) {
    if (grid[i][col] != 0)
    break;
    vis[i][col] = 1;
    }
    }
    void solve3(vector& grid, vector& vis, int i,
    int j) {
    int m = grid.size(), n = grid[0].size();
    for (int row = i + 1; row < m; row++) {
    if (grid[row][j] != 0)
    break;
    vis[row][j] = 1;
    }
    }
    void solve4(vector& grid, vector& vis, int i,
    int j) {
    int m = grid.size(), n = grid[0].size();
    for (int row = i - 1; row >= 0; row--) {
    if (grid[row][j] != 0)
    break;
    vis[row][j] = 1;
    }
    }
    int countUnguarded(int m, int n, vector& guards,
    vector& walls) {
    vector grid(m, vector(n, 0));
    vector vis(m, vector(n, 0));
    for (auto guard : guards) {
    grid[guard[0]][guard[1]] = 1;
    }
    for (auto wall : walls) {
    grid[wall[0]][wall[1]] = -1;
    }
    for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
    if (grid[i][j] == 1) {
    solve1(grid, vis, i, j);
    solve2(grid, vis, i, j);
    solve3(grid, vis, i, j);
    solve4(grid, vis, i, j);
    }
    }
    }
    int ans = 0;
    for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
    if (grid[i][j] == 0 && vis[i][j] == 0)
    ans++;
    }
    }
    return ans;
    }
    };

  • @Anonymous____________A721
    @Anonymous____________A721 2 วันที่ผ่านมา

    Brooo
    Y u changed to confluent??

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

      3 digit % increase + Learning Opportunities & Growth sir :)

    • @Anonymous____________A721
      @Anonymous____________A721 2 วันที่ผ่านมา +1

      @ARYANMITTAL 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥