File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed
2025-01-January-LeetCoding-Challenge Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1+ from itertools import product
2+ from typing import List
3+
4+
5+ class Solution :
6+ def countServers (self , grid : List [List [int ]]) -> int :
7+ m , n = len (grid ), len (grid [0 ])
8+ row_sums , col_sums = [0 ] * m , [0 ] * n
9+ servers = []
10+
11+ for x , y in product (range (m ), range (n )):
12+ if grid [x ][y ] == 0 :
13+ continue
14+ row_sums [x ] += 1
15+ col_sums [y ] += 1
16+ servers .append ((x , y ))
17+
18+ count = 0
19+ for x , y in servers :
20+ if row_sums [x ] > 1 or col_sums [y ] > 1 :
21+ count += 1
22+ return count
23+
24+
25+ def main ():
26+ grid = [[1 , 0 ],
27+ [0 , 1 ]]
28+ assert Solution ().countServers (grid ) == 0
29+
30+ grid = [[1 , 0 ],
31+ [1 , 1 ]]
32+ assert Solution ().countServers (grid ) == 3
33+
34+ grid = [[1 , 1 , 0 , 0 ],
35+ [0 , 0 , 1 , 0 ],
36+ [0 , 0 , 1 , 0 ],
37+ [0 , 0 , 0 , 1 ]]
38+ assert Solution ().countServers (grid ) == 4
39+
40+
41+ if __name__ == '__main__' :
42+ main ()
Original file line number Diff line number Diff line change 2525| January 20 | [ 2661. First Completely Painted Row or Column] ( https://leetcode.com/problems/first-completely-painted-row-or-column/ ) | Medium | Solved |
2626| January 21 | [ 2017. Grid Game] ( https://leetcode.com/problems/grid-game/ ) | Medium | Solved |
2727| January 22 | [ 1765. Map of Highest Peak] ( https://leetcode.com/problems/map-of-highest-peak/ ) | Medium | Solved |
28- | January 23 | [ ] ( ) | | |
28+ | January 23 | [ 1267. Count Servers that Communicate ] ( https://leetcode.com/problems/count-servers-that-communicate/ ) | Medium | Solved |
2929| January 24 | [ ] ( ) | | |
3030| January 25 | [ ] ( ) | | |
3131| January 26 | [ ] ( ) | | |
4040| Level | Problems | Solved | Unsolved |
4141| --- | --- | --- | --- |
4242| Easy | 4 | 4 | 0 |
43- | Medium | 15 | 13 | 2 |
43+ | Medium | 16 | 14 | 2 |
4444| Hard | 2 | 0 | 2 |
You can’t perform that action at this time.
0 commit comments