1267. Count Servers that Communicate | leetcode daily challenge | shashcode | java | dsa | shashwat

preview_player
Показать описание
Problem Link:

Problem Statement:
You are given a map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two servers are said to communicate if they are on the same row or on the same column.

Return the number of servers that communicate with any other server.

Solution Link:

Custom Comparator:

Lambda Expression:

Dynamic Programming:

Graph Playlist:

Java Plus DSA Placement Course Playlist:

Java Plus DSA Sheet:

Notes:

Telegram Link:

Ultimate Recursion Series Playlist:

Samsung Interview Experience:

Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung

Timestamp:
0:00 - Introduction
Рекомендации по теме
Комментарии
Автор

like target is 170. Please do like if you understood the explanation as well as the code.😊😊

shashwat_tiwari_st
Автор

class Solution {
public int countServers(int[][] grid) {
int m = grid.length;
int n = grid[0].length;
int[] rowPref = new int[m];
int[] colPref = new int[n];
for(int i=0;i<m;i++){
int sum = 0;
for(int j=0;j<n;j++){
sum += grid[i][j];
}
rowPref[i] = sum;
}
for(int j=0;j<n;j++){
int sum = 0;
for(int i=0;i<m;i++){
sum += grid[i][j];
}
colPref[j] = sum;
}
int cnt = 0;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(grid[i][j]==1){
if(rowPref[i]>1 || colPref[j]>1){
cnt++;
}
}
}
}
return cnt;
}
}

VardanTyagi-vd
Автор

sir, 2 din pehle wala solution hi hai, mst chal gaya 😛😋

PiyushSharma-weyd
Автор

which hardware do u use to draw on screen?

devnarula
Автор

sir aapne java+dsa ki playlist me Quicksort, Mergesort padaya he nahi

kalpeshrathod
Автор

Tried to use the approach of no of islands(dfs) by grouping elements code became too lengthy

DarkDragon-bzqp
visit shbcf.ru