question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
maximum-product-of-three-numbers
Python beats 100% & 100% in two ways easy understand nO(logn) & O(n)
python-beats-100-100-in-two-ways-easy-un-mip6
python\n def maximumProduct(self, nums: List[int]) -> int:\n nums.sort()\n return max(nums[0]*nums[1]*nums[-1] , nums[-1]*nums[-2]*nums[-3])\n\
macqueen
NORMAL
2019-11-13T10:15:36.031528+00:00
2019-11-13T10:15:36.031567+00:00
316
false
```python\n def maximumProduct(self, nums: List[int]) -> int:\n nums.sort()\n return max(nums[0]*nums[1]*nums[-1] , nums[-1]*nums[-2]*nums[-3])\n```\nsort make a n*log(n) time and it beats 100% and 100%\nthis way can only solve in three numbers\nsecond way is a normal idea solve a normal problom:\n\n``...
3
1
[]
0
maximum-product-of-three-numbers
Easy solution - without sorting
easy-solution-without-sorting-by-pooja04-t5o3
Runtime: 44 ms, faster than 92.47% of C++ online submissions for Maximum Product of Three Numbers.\nMemory Usage: 10.9 MB, less than 100.00% of C++ online submi
pooja0406
NORMAL
2019-08-23T07:08:17.619807+00:00
2019-08-23T07:08:17.619843+00:00
492
false
Runtime: 44 ms, faster than 92.47% of C++ online submissions for Maximum Product of Three Numbers.\nMemory Usage: 10.9 MB, less than 100.00% of C++ online submissions for Maximum Product of Three Numbers.\n\n```\nint maximumProduct(vector<int>& nums) {\n \n int n = nums.size();\n int minOne = INT_M...
3
0
['C++']
1
maximum-product-of-three-numbers
Python solution
python-solution-by-zitaowang-393d
O(n log n) time O(n) space:\n\nclass Solution(object):\n def maximumProduct(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n
zitaowang
NORMAL
2018-10-12T16:06:07.260184+00:00
2018-10-23T15:45:20.965435+00:00
539
false
O(n log n) time O(n) space:\n```\nclass Solution(object):\n def maximumProduct(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n nums = sorted(nums)\n if nums[0] >= 0:\n return nums[-3]*nums[-2]*nums[-1]\n elif nums[1] < 0:\n retur...
3
0
[]
0
maximum-product-of-three-numbers
Python Easy with Explaination
python-easy-with-explaination-by-reknix-shmv
\ndef maximumProduct(self, nums):\n nums.sort()\n max_num = 0\n # if all negative, or all positive, or only one negative number. In this case, take 3 r
reknix
NORMAL
2017-06-25T03:11:34.771000+00:00
2017-06-25T03:11:34.771000+00:00
621
false
```\ndef maximumProduct(self, nums):\n nums.sort()\n max_num = 0\n # if all negative, or all positive, or only one negative number. In this case, take 3 rightmost number \n if nums[-1] < 0 or nums[0] >= 0 or (nums[0] < 0 and nums[1] > 0):\n max_num = nums[-1] * nums[-2] * nums[-3]\n # if two or mo...
3
0
[]
0
maximum-product-of-three-numbers
BEST C++ SOLUTION || BEATS 100% || EASY EXPLANATION ||
best-c-solution-beats-100-easy-explanati-omht
IntuitionFind the three largest numbers.Find the two smallest numbers (to handle cases with negative numbers).Compute both possible products:largest1 * largest2
rameeta
NORMAL
2025-02-18T18:47:02.925397+00:00
2025-02-18T18:56:31.288184+00:00
445
false
# Intuition Find the three largest numbers. Find the two smallest numbers (to handle cases with negative numbers). Compute both possible products: largest1 * largest2 * largest3 smallest1 * smallest2 * largest1 Return the maximum of the two. # Approach Instead of sorting (which is O(N log N)), we can find the top thre...
2
0
['C++']
0
maximum-product-of-three-numbers
Java || Single-Pass Linear Scan || time complexity : O(n)
java-single-pass-linear-scan-time-comple-lqy7
Complexity Time complexity: O(n) Space complexity: O(1) Code
shikhargupta0645
NORMAL
2025-02-02T02:34:01.405800+00:00
2025-02-02T02:34:01.405800+00:00
574
false
# Complexity - Time complexity: O(n) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```java [] class Solution { public int maximumProduct(int[] nums) { int max1 = Integer.MIN_VALUE; int max2 = Integer.M...
2
0
['Java']
0
maximum-product-of-three-numbers
BEATS 100%, O(N), SOLUTION
beats-100-on-solution-by-sahil_sr7-khnu
Intuition 🤔To find the maximum product of three numbers in an array, we need to consider both the largest three numbers (positive or negative) and the smallest
sahilrashid10
NORMAL
2025-01-28T09:48:12.792756+00:00
2025-01-28T09:48:12.792756+00:00
509
false
# Intuition 🤔 To find the maximum product of three numbers in an array, we need to consider both the largest three numbers (positive or negative) and the smallest two numbers (in case they are negative) combined with the largest number. This ensures that we capture both possible scenarios for the highest product. # A...
2
0
['C++']
0
maximum-product-of-three-numbers
Finding the GOLDEN Trio ✨ | 2 Methods 🔥 | Simple Explanation + Illustration ⭐ | JAVA 🚀
finding-the-golden-trio-2-methods-simple-402q
IntuitionTo find the maximum product of any three numbers in an array, we must consider two scenarios:The three largest numbers in the array. The two smallest n
supreme_undy014
NORMAL
2025-01-26T14:35:54.607272+00:00
2025-01-26T14:39:41.141289+00:00
259
false
# Intuition To find the maximum product of any three numbers in an array, we must consider two scenarios: The three largest numbers in the array. The two smallest numbers (most negative) multiplied by the largest number. This is because two negative numbers produce a positive product, which might be larger than the pr...
2
0
['Array', 'Math', 'Java']
0
maximum-product-of-three-numbers
Easy one liner solution
easy-one-liner-solution-by-karan-s1ngh-xyuc
Approachnum.sort() sorts the list in ascending ordernums[-1]*nums[-2]*nums[-3] gives the product of 3 maximum number (positive)nums[0]*nums[1]*nums[-1] gives th
Karan-S1ngh
NORMAL
2024-12-28T17:32:06.278641+00:00
2024-12-30T19:57:32.780408+00:00
492
false
# Approach num.sort() sorts the list in ascending order nums[-1]*nums[-2]*nums[-3] gives the product of 3 maximum number (positive) nums[0]*nums[1]*nums[-1] gives the product of 2 biggest negative number not considering the negative sign and the biggest positive number. This is done as product of 2 negative number is...
2
0
['Python3']
0
maximum-product-of-three-numbers
Easy Solution in Java
easy-solution-in-java-by-tamilarasanmuru-z6ul
Intuition\nTo find the maximum product of three numbers from the array, there are two possible candidates:\n\n1.The product of the largest three numbers in the
TamilarasanMurugan
NORMAL
2024-09-25T10:05:31.187498+00:00
2024-09-25T10:05:31.187535+00:00
40
false
# Intuition\nTo find the maximum product of three numbers from the array, there are two possible candidates:\n\n1.The product of the largest three numbers in the array.\n2.The product of the two smallest numbers (possibly negative) and the largest number (as multiplying two negatives results in a positive product).\nTh...
2
0
['Array', 'Math', 'Sorting', 'Java']
0
maximum-product-of-three-numbers
ayyo rama it was this :D
ayyo-rama-it-was-this-d-by-yesyesem-ef3e
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
yesyesem
NORMAL
2024-09-16T05:00:15.838290+00:00
2024-09-16T05:00:15.838335+00:00
432
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['C++']
0
maximum-product-of-three-numbers
Simple Python Solution
simple-python-solution-by-started_coding-f945
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
started_coding_again
NORMAL
2024-09-02T05:23:59.069684+00:00
2024-09-02T05:23:59.069709+00:00
249
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Python3']
0
maximum-product-of-three-numbers
Without Sorting || Easy to UnderStand || 99% Beats
without-sorting-easy-to-understand-99-be-iaxa
Intuition\nBy maintaining the three largest and two smallest numbers while iterating through the array, we can compute the maximum product without sorting the a
tinku_tries
NORMAL
2024-07-01T05:46:35.791200+00:00
2024-07-01T05:46:35.791223+00:00
1,683
false
# Intuition\nBy maintaining the three largest and two smallest numbers while iterating through the array, we can compute the maximum product without sorting the array.\n\n# Approach\n1. **Initialize Variables:** Use variables to store the three largest and two smallest numbers.\n2. **Single Pass Through Array:** Update...
2
0
['Array', 'Math', 'C++']
1
maximum-product-of-three-numbers
Easy approach in C++
easy-approach-in-c-by-shatakshi_sharma06-4mt8
Intuition\nTo find maximum at first i thught just to find the max by sorting . ANd i did the same . But we have to check for an extra condition for -ve ones\n D
Shatakshi_Sharma06
NORMAL
2024-05-12T20:40:07.884002+00:00
2024-05-12T20:40:07.884032+00:00
870
false
# Intuition\nTo find maximum at first i thught just to find the max by sorting . ANd i did the same . But we have to check for an extra condition for -ve ones\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nFirst sort the vector which will make it easy to iterate directly on indices....
2
0
['C++']
1
maximum-product-of-three-numbers
💯Java beginner friendly solution
java-beginner-friendly-solution-by-jeril-gxcf
Intuition\nThe intuition behind this approach is to sort the array in ascending order. Once the array is sorted, the maximum product can be achieved by either m
jeril-johnson
NORMAL
2023-12-27T09:59:42.722060+00:00
2023-12-27T09:59:42.722092+00:00
903
false
# Intuition\nThe intuition behind this approach is to sort the array in ascending order. Once the array is sorted, the maximum product can be achieved by either multiplying the three largest numbers or the two smallest and the largest number. By comparing both possibilities, the maximum product can be determined.\n\n# ...
2
0
['Java']
2
maximum-product-of-three-numbers
O(NlogN) ➡️O(N) ||Beats 100% || Two Java Approaches
onlogn-on-beats-100-two-java-approaches-co8b8
Approach\nSort the array: so three max numbers are in the end of the array, two negative numbers whose product will be max will be on the start of the array.\n
Shivansu_7
NORMAL
2023-12-11T18:12:03.600780+00:00
2023-12-11T18:12:03.600813+00:00
894
false
# Approach\n**Sort the array:** so three max numbers are in the end of the array, two negative numbers whose product will be max will be on the start of the array.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N*logN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$...
2
0
['Java']
1
contain-virus
CPP DFS solution explained
cpp-dfs-solution-explained-by-rai02-znvl
I recently got this in an assessment. \n\nget clusters in every step. \n\ndeal with the largest clusters and expand all the other clusters.\n\nlets take the sam
rai02
NORMAL
2020-09-15T07:41:26.086341+00:00
2020-09-15T07:46:49.164203+00:00
6,978
false
I recently got this in an assessment. \n\nget clusters in every step. \n![image](https://assets.leetcode.com/users/images/2fba1bf5-a2e6-4a08-9f3b-1c204d76a2ac_1600154624.5271661.png)\ndeal with the largest clusters and expand all the other clusters.\n\nlets take the sample case\n![image](https://assets.leetcode.com/use...
99
0
['Depth-First Search', 'C++']
15
contain-virus
Java, DFS, 9 ms, Explanation with comments
java-dfs-9-ms-explanation-with-comments-4ju0b
This class Region hold the information for each region.\n\nprivate class Region {\n // Using Set<Integer> instead of List<int[]> (int[] -> row and col pair),
gagarwal
NORMAL
2020-03-02T18:57:36.239401+00:00
2020-03-05T03:59:50.153127+00:00
6,421
false
This class **Region** hold the information for each region.\n```\nprivate class Region {\n // Using Set<Integer> instead of List<int[]> (int[] -> row and col pair),\n // as need to de-dupe the elements.\n // If N rows and M cols.\n // Total elements = NxM.\n // Given row and col calculate X as: X = row *...
45
0
['Depth-First Search', 'Java']
10
contain-virus
C++, DFS, 12ms
c-dfs-12ms-by-zestypanda-p90f
The solution simply models the process. \n1) Build walls = set those connected virus inactive, i.e. set as -1;\n2) Affected area != walls; For example, one 0 su
zestypanda
NORMAL
2017-12-17T06:59:49.839000+00:00
2017-12-17T06:59:49.839000+00:00
5,633
false
The solution simply models the process. \n1) Build walls = set those connected virus inactive, i.e. set as -1;\n2) Affected area != walls; For example, one 0 surrounded by all 1s have area = 1, but walls = 4.\n\nDFS\n```\nclass Solution {\npublic:\n int containVirus(vector<vector<int>>& grid) {\n int ans = 0;...
17
0
[]
2
contain-virus
Contain the virus, contain the new coronavirus, fighting...
contain-the-virus-contain-the-new-corona-44ki
\n\ndef containVirus(self, grid: List[List[int]]) -> int:\n m=len(grid)\n n=len(grid[0])\n dirs=[(0,1),(1,0),(0,-1),(-1,0)]\n \n
foster2
NORMAL
2020-01-23T21:45:11.437462+00:00
2020-01-23T21:45:11.437498+00:00
1,998
false
\n```\ndef containVirus(self, grid: List[List[int]]) -> int:\n m=len(grid)\n n=len(grid[0])\n dirs=[(0,1),(1,0),(0,-1),(-1,0)]\n \n def dfs(x,y,sn):\n if grid[x][y]==1:\n v[sn].add((x,y))\n seen.add((x,y))\n for dx,dy in dirs:\n ...
10
1
[]
0
contain-virus
Pyhon Easy Solution || DFS || Time O(m*n*max(m , n)) || Faster
pyhon-easy-solution-dfs-time-omnmaxm-n-f-enja
\n class Solution:\n def containVirus(self, mat: List[List[int]]) -> int:\n m,n = len(mat),len(mat[0])\n\n def dfs(i,j,visited,nextInfected):
Laxman_Singh_Saini
NORMAL
2022-07-01T22:00:47.331524+00:00
2022-07-02T17:35:10.981765+00:00
2,117
false
```\n class Solution:\n def containVirus(self, mat: List[List[int]]) -> int:\n m,n = len(mat),len(mat[0])\n\n def dfs(i,j,visited,nextInfected): # return no. of walls require to quarantined dfs area\n if 0<=i<m and 0<=j<n and (i,j) not in visited:\n if mat[i][j]==2: # Already...
9
0
['Depth-First Search', 'Python', 'Python3']
1
contain-virus
C++ DFS simulation (20 ms)
c-dfs-simulation-20-ms-by-leetcode07-r1no
After each dfs, the matrix can contain only three types of numbers:\na) 1: infected cell\nb) 0: healthy cell\nc) 1e9: blocked cell\n\n2. If no cell becomes infe
leetcode07
NORMAL
2020-07-24T09:58:40.524242+00:00
2020-07-24T10:00:55.927496+00:00
1,763
false
1. After each dfs, the matrix can contain only three types of numbers:\na) 1: infected cell\nb) 0: healthy cell\nc) 1e9: blocked cell\n\n2. If no cell becomes infected the following night, the simulation breaks and returns answer\n\n3. The unordered set is used to find the total number of cells infected by a connected ...
7
0
[]
0
contain-virus
Commented Python using DFS with explanation
commented-python-using-dfs-with-explanat-qbe4
Find most threatening region (would infect most normal cells next night) via DFS and at same time count the walls needed to wall off, and return it\'s coordinat
fortuna911
NORMAL
2019-02-02T20:23:22.865630+00:00
2019-02-02T20:23:22.865693+00:00
1,015
false
1. Find most threatening region (would infect most normal cells next night) via DFS and at same time count the walls needed to wall off, and return it\'s coordinates\n2. Quarantine that region by doing DFS and walling that region off by setting 1\'s to -1\'s\n3. Simulate night virus spread: find a \'1\' do a DFS on it ...
7
0
[]
0
contain-virus
[Contian Virus] Do I misunstand something?
contian-virus-do-i-misunstand-something-mocz6
For input \n[[0,1,0,1,1,1,1,1,1,0],\n[0,0,0,1,0,0,0,0,0,0],\n[0,0,1,1,1,0,0,0,1,0],\n[0,0,0,1,1,0,0,1,1,0],\n[0,1,0,0,1,0,1,1,0,1],\n[0,0,0,1,0,1,0,1,1,1],\n[0,
arnoldlee
NORMAL
2018-01-06T21:59:25.283000+00:00
2018-01-06T21:59:25.283000+00:00
1,409
false
For input \n[[0,1,0,1,1,1,1,1,1,0],\n[0,0,0,1,0,0,0,0,0,0],\n[0,0,1,1,1,0,0,0,1,0],\n[0,0,0,1,1,0,0,1,1,0],\n[0,1,0,0,1,0,1,1,0,1],\n[0,0,0,1,0,1,0,1,1,1],\n[0,1,0,0,1,0,0,1,1,0],\n[0,1,0,1,0,0,0,1,1,0],\n[0,1,1,0,0,1,1,0,0,1],\n[1,0,1,1,0,1,0,1,0,1]]\nMy solution gives answer=40 but the answer=38. \nI calculated manua...
7
0
[]
2
contain-virus
A Visualization Tool
a-visualization-tool-by-rowe1227-64cq
This is a tricky problem to debug, however visualizing the spread of the virus helps.\nHere is a visualization tool that shows how the grid changes each day.\n1
rowe1227
NORMAL
2020-11-10T21:26:00.760663+00:00
2020-11-10T22:21:56.783135+00:00
835
false
This is a tricky problem to debug, however visualizing the spread of the virus helps.\nHere is a visualization tool that shows how the grid changes each day.\n1 means the cell is infected and 2 means the cell has been contained with walls.\nHere is an example output with a few notes added:\n\n```html5\n<b>Grid status o...
5
0
[]
0
contain-virus
Concise c++ solution with BFS, 12ms
concise-c-solution-with-bfs-12ms-by-mzch-k0f0
\nint containVirus(vector<vector<int>>& g) {\n int res = 0, c = 1; // c increments for visited cells\n\n while (true) {\n // tuple components: wall
mzchen
NORMAL
2017-12-17T09:49:04.129000+00:00
2018-08-10T22:13:23.899539+00:00
2,108
false
```\nint containVirus(vector<vector<int>>& g) {\n int res = 0, c = 1; // c increments for visited cells\n\n while (true) {\n // tuple components: walls, inside coords with value c, border coords with value 0\n vector<tuple<int, vector<pair<int, int>>, set<pair<int, int>>>> areas;\n int mx = 0...
5
0
[]
1
contain-virus
My Neat Java Solution Using Dfs
my-neat-java-solution-using-dfs-by-llz01-hbv8
\nclass Solution {\n public int containVirus(int[][] grid) {\n int[] cost = new int[]{0};\n while(check(grid, cost));\n return cost[0];\
llz0108
NORMAL
2017-12-20T01:29:53.196000+00:00
2018-10-10T16:06:09.957671+00:00
2,617
false
```\nclass Solution {\n public int containVirus(int[][] grid) {\n int[] cost = new int[]{0};\n while(check(grid, cost));\n return cost[0];\n }\n \n private boolean check(int[][] grid, int[] cost) {\n// update every day information and return false if no improvement can be made\n ...
5
0
[]
3
contain-virus
c++ | Exactly what the hint said
c-exactly-what-the-hint-said-by-shourabh-bvns
Algorithm\n1. Iterate over all regions and get the coordinates of region with maximum area threatened\n2. Mark the max threatened region obtained in step 1 as -
shourabhpayal
NORMAL
2021-06-23T09:28:36.029737+00:00
2021-06-23T09:28:57.270208+00:00
1,092
false
**Algorithm**\n1. Iterate over all regions and get the coordinates of region with maximum area threatened\n2. Mark the max threatened region obtained in step 1 as -1 signifying it is disinfected. Add perimeter to answer.\n3. Expand the remaining regions\n4. Repeat step 1 to 3 till max area threatened = 0\n\n***Note:***...
4
0
['Depth-First Search', 'C']
0
contain-virus
749: Solution with step by step explanation
749-solution-with-step-by-step-explanati-44vj
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\nm, n = len(mat), len(mat[0])\nDIRECTIONS = [(-1, 0), (1, 0), (0, -1), (
Marlen09
NORMAL
2023-10-22T17:43:33.600875+00:00
2023-10-22T17:43:33.600907+00:00
532
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n```\nm, n = len(mat), len(mat[0])\nDIRECTIONS = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n```\nm and n capture the dimensions of the matrix.\nDIRECTIONS is a list of four possible moves from a cell: up, down, left, and right.\n\n`...
3
0
['Array', 'Depth-First Search', 'Breadth-First Search', 'Matrix', 'Simulation', 'Python', 'Python3']
0
contain-virus
Trying to understand a test case
trying-to-understand-a-test-case-by-magi-7ed7
Can someone please explain why the expected output is 38 for the below input?\n\nInput:\n[[0,1,0,1,1,1,1,1,1,0],[0,0,0,1,0,0,0,0,0,0],[0,0,1,1,1,0,0,0,1,0],[0,0
magicgnome
NORMAL
2018-11-04T20:35:56.962907+00:00
2018-11-04T20:35:56.962946+00:00
471
false
Can someone please explain why the expected output is 38 for the below input?\n\nInput:\n[[0,1,0,1,1,1,1,1,1,0],[0,0,0,1,0,0,0,0,0,0],[0,0,1,1,1,0,0,0,1,0],[0,0,0,1,1,0,0,1,1,0],[0,1,0,0,1,0,1,1,0,1],[0,0,0,1,0,1,0,1,1,1],[0,1,0,0,1,0,0,1,1,0],[0,1,0,1,0,0,0,1,1,0],[0,1,1,0,0,1,1,0,0,1],[1,0,1,1,0,1,0,1,0,1]]\n\nExpect...
3
0
[]
3
contain-virus
I can Guarantee you that The Cleanest Code You'll Ever See with Best in class Explanation !!!
i-can-guarantee-you-that-the-cleanest-co-w6zy
Intuition :- Simulation Max Heap DFS Approach :- Helper Classes :- Pair Class : row - To store the row of a cell. column- To store the column of cell. Regi
Jagadish_Shankar
NORMAL
2024-12-13T10:57:12.055809+00:00
2024-12-13T11:05:10.168989+00:00
250
false
# Intuition :-\n\n- Simulation\n- Max Heap\n- DFS\n\n# Approach :-\n\n1) **Helper Classes :-**\n\n 1) ```Pair``` Class :\n - ```row``` - To store the row of a cell.\n - ```column```- To store the column of cell.\n \n 2) ```Region_Data``` Class :\n - ```walls_required_count``` - Number of w...
2
0
['Depth-First Search', 'Breadth-First Search', 'Heap (Priority Queue)', 'Matrix', 'Simulation', 'Java']
0
contain-virus
BEAT 100% || C++
beat-100-c-by-antony_ft-mnkh
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
antony_ft
NORMAL
2023-07-30T15:57:21.686185+00:00
2023-07-30T15:57:21.686202+00:00
116
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['C++']
0
contain-virus
BFS: A Step-by-Step Guide with Comments.
bfs-a-step-by-step-guide-with-comments-b-qvfu
Template for BFS\n\n1. bfs = deque() # to store the node first meets the requirements\n2. while bfs: # there are still nodes to visit\n3. node = bfs.popleft
ShutingLuo
NORMAL
2023-03-05T15:29:44.597770+00:00
2023-03-05T15:29:44.597813+00:00
245
false
# Template for BFS\n```\n1. bfs = deque() # to store the node first meets the requirements\n2. while bfs: # there are still nodes to visit\n3. node = bfs.popleft()\n4. # Mark as visited\n5. # Expand the node in all four directions\n6. if not visited and within the valid range:\n7. # update and d...
2
0
['Breadth-First Search', 'Python3']
0
contain-virus
c++ | easy | short
c-easy-short-by-venomhighs7-rwyi
\n# Code\n\nclass Solution {\npublic:\n vector<vector<int> > g;\n int n, m, c, mx, w, r, ans, itr;\n unordered_set<int> s;\n \n int dfs(int i, in
venomhighs7
NORMAL
2022-11-01T03:48:19.595344+00:00
2022-11-01T03:48:19.595388+00:00
1,363
false
\n# Code\n```\nclass Solution {\npublic:\n vector<vector<int> > g;\n int n, m, c, mx, w, r, ans, itr;\n unordered_set<int> s;\n \n int dfs(int i, int j){\n if(i<0 || i>=n || j<0 || j>=m || g[i][j]!=1)\n return 0;\n int ans=0;\n if(i+1<n && g[i+1][j]==0){\n s.ins...
2
0
['C++']
0
contain-virus
[Python3] brute-force
python3-brute-force-by-ye15-4css
\n\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n m, n = len(isInfected), len(isInfected[0])\n ans = 0 \n
ye15
NORMAL
2022-09-06T02:59:01.697884+00:00
2022-09-06T03:08:06.464095+00:00
656
false
\n```\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n m, n = len(isInfected), len(isInfected[0])\n ans = 0 \n while True: \n regions = []\n fronts = []\n walls = []\n seen = set()\n for i in range(m): \n ...
2
0
['Python3']
0
contain-virus
Python BFS simulation solution: nothing convoluted
python-bfs-simulation-solution-nothing-c-nlbp
I guess one should attempt Leetcode 695. Max Area of Island before doing this problem. Just speeds up everything tremendously, no complicated algorithms or conc
huikinglam02
NORMAL
2022-06-30T18:24:27.926714+00:00
2022-06-30T18:24:27.926757+00:00
481
false
I guess one should attempt Leetcode 695. Max Area of Island before doing this problem. Just speeds up everything tremendously, no complicated algorithms or concepts at all\nAlso, I highly recommend padding the boundary with 2, as a rigid wall is equivalent to a quarantined region\n```\nclass Solution:\n # Use 2 to p...
2
0
[]
0
contain-virus
Easy to understand | DFS
easy-to-understand-dfs-by-bnybny-fs7t
\nclass Group{\n public:\n \n set<pair<int,int>>ne;\n set<pair<int,int>>affected;\n \n int w;\n \n Group(){\n w = 0;\n }\n};\n
bnybny
NORMAL
2022-06-22T20:11:07.585938+00:00
2022-06-22T20:16:13.725933+00:00
812
false
```\nclass Group{\n public:\n \n set<pair<int,int>>ne;\n set<pair<int,int>>affected;\n \n int w;\n \n Group(){\n w = 0;\n }\n};\n\n\n\nclass Solution {\npublic:\n \n bool isValid(int i,int j,int n,int m){\n return i>=0 && j>=0 && i<n && j<m;\n }\n \n int dir[4][2]...
2
0
['Depth-First Search', 'C']
0
contain-virus
Java clean
java-clean-by-rexue70-2fvi
Very short Java\n\n1. we calculate score of island(means how many island it can infect next), border of island\n2. pick the max score island and delete it, add
rexue70
NORMAL
2020-05-08T05:46:15.315156+00:00
2020-05-08T05:47:55.425388+00:00
671
false
Very short Java\n\n1. we calculate score of island(means how many island it can infect next), border of island\n2. pick the max score island and delete it, add border of that island to result\n3. extend infection to next day, all remaining island expand.\n\n```\nclass Solution {\n int m, n, id;\n int[][] dirs = {...
2
0
[]
0
contain-virus
longest solution I've ever written on leetcode. 1A, love u all
longest-solution-ive-ever-written-on-lee-8hcs
\nclass Pos {\n int x;\n int y;\n\n Pos(int x, int y) {\n this.x = x;\n this.y = y;\n }\n}\n\nclass Solution {\n private static fin
solaaoi
NORMAL
2018-04-21T03:35:11.522155+00:00
2018-04-21T03:35:11.522155+00:00
600
false
```\nclass Pos {\n int x;\n int y;\n\n Pos(int x, int y) {\n this.x = x;\n this.y = y;\n }\n}\n\nclass Solution {\n private static final int MAX_N = 50;\n private static final int dr[] = {-1, 1, 0, 0};\n private static final int dc[] = {0, 0, -1, 1};\n\n private static boolean[][] ...
2
0
[]
0
contain-virus
Concise solution, no index tracking (detailed explanation with illustration)
concise-solution-no-index-tracking-detai-5sz2
The idea is to find all infected regions and identify the most dangerous one (i.e., infecting most uninfected cells), then update all regions by the rule and re
zzg_zzm
NORMAL
2017-12-19T05:59:23.594000+00:00
2017-12-19T05:59:23.594000+00:00
649
false
The idea is to find all infected regions and identify the most dangerous one (i.e., infecting most uninfected cells), then update all regions by the rule and repeat this process until no more infected regions found.\n\nTo accomplish this algorithm, it is useful to define structure `Region` as\n```cpp\n struct Region...
2
0
['Depth-First Search', 'C++']
1
contain-virus
clean python solution
clean-python-solution-by-erjoalgo-8eto
\nclass Solution(object):\n def containVirus(self, grid):\n """\n :type grid: List[List[int]]\n :rtype: int\n """\n if not
erjoalgo
NORMAL
2017-12-17T23:20:58.157000+00:00
2017-12-17T23:20:58.157000+00:00
969
false
```\nclass Solution(object):\n def containVirus(self, grid):\n """\n :type grid: List[List[int]]\n :rtype: int\n """\n if not grid: return None\n N,M=len(grid),len(grid[0])\n \n def around(r,c,t=None):\n # all cells 1-step away from (r,c)\n ...
2
0
[]
2
contain-virus
Contain Virus Question
contain-virus-question-by-amphitter-kr35
\n# Intuition\n- Identify Infected Regions: Use BFS or DFS to find all contiguous regions of infected cells (cells with value 1).\n\n- Calculate Threats and Wal
Amphitter
NORMAL
2024-05-24T05:51:51.622364+00:00
2024-05-24T05:51:51.622394+00:00
106
false
\n# Intuition\n- Identify Infected Regions: Use BFS or DFS to find all contiguous regions of infected cells (cells with value 1).\n\n- Calculate Threats and Walls: For each infected region, determine the number of uninfected cells it can potentially infect in the next step and calculate the number of walls needed to qu...
1
0
['Python']
0
contain-virus
Another Explanation, Python3, O(R*C*max(R,C)) time and O(R*C) space, Faster than 95%
another-explanation-python3-orcmaxrc-tim-q7ze
Intuition\n Describe your first thoughts on how to solve this problem. \n\nThis is a pretty hard problem, there\'s a lot going on. There are a lot of considerat
biggestchungus
NORMAL
2023-07-25T02:08:33.453512+00:00
2023-07-25T02:08:33.453535+00:00
92
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThis is a pretty hard problem, there\'s a lot going on. There are a lot of considerations to make. But the idea is that the problem asks us to wall of clusters according to what happens each day/night, and explains the rules. So we simu...
1
0
['Python3']
0
contain-virus
ONE OF THE HARDEST QUESTIONS I EVER SOLVED || DFS || 30 MS || JAVA
one-of-the-hardest-questions-i-ever-solv-ih9h
Code\n\nclass AreaInfo {\n Set<List<Integer>> nodes;\n int id;\n int numExposed;\n\n public AreaInfo(int id) {\n this.nodes = new HashSet<>()
youssef1998
NORMAL
2023-06-19T08:38:55.968755+00:00
2023-06-19T08:38:55.968797+00:00
558
false
# Code\n```\nclass AreaInfo {\n Set<List<Integer>> nodes;\n int id;\n int numExposed;\n\n public AreaInfo(int id) {\n this.nodes = new HashSet<>();\n this.id = id;\n this.numExposed = 0;\n }\n}\n\nclass Solution {\n private final int HEALTHY = 0, UNHEALTHY = 1, FOUND = 2, CONTAMIN...
1
0
['Depth-First Search', 'Sorting', 'Matrix', 'Java']
0
contain-virus
Solution
solution-by-deleted_user-93l6
C++ []\nint mp[2652], *zp[2652], zc[2652], step, mk;\n\nint dfs(int *p) {\n *p = 2;\n int res = 0;\n for (int *nb : {p-step, p-1, p+1, p+step}) {\n
deleted_user
NORMAL
2023-04-24T09:17:36.704495+00:00
2023-04-24T09:48:24.746491+00:00
1,638
false
```C++ []\nint mp[2652], *zp[2652], zc[2652], step, mk;\n\nint dfs(int *p) {\n *p = 2;\n int res = 0;\n for (int *nb : {p-step, p-1, p+1, p+step}) {\n int v = *nb;\n if (v == mk || v > 1) continue;\n if (v <= 0) *nb = mk, ++res; else res += dfs(nb);\n }\n return res;\n}\nint dfs2(int...
1
0
['C++', 'Java', 'Python3']
0
contain-virus
DFS + Heap
dfs-heap-by-bbblair-256c
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n # isInfected: 0 for uninfected; 1 for infected; -1 for contained;\n
bbblair
NORMAL
2022-09-30T22:35:26.421635+00:00
2022-09-30T22:35:26.421668+00:00
128
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n # isInfected: 0 for uninfected; 1 for infected; -1 for contained;\n # use DFS to traverse the whole board to find \n # - the infected area (any cell);\n # - its risky cells;\n # - the number of walls needed t...
1
1
['Python3']
0
contain-virus
DFS with "marker" , 15 ms
dfs-with-marker-15-ms-by-mrn3088-6xp7
This problem is just a simulation.\nThe whole process is:\n1. Find which group of virus would infect most uninfected area. If no group of virus could infect mor
mrn3088
NORMAL
2022-07-18T07:54:05.557765+00:00
2022-07-18T07:54:05.557812+00:00
578
false
This problem is just a simulation.\nThe whole process is:\n1. Find which group of virus would infect most uninfected area. If no group of virus could infect more uninfected area, break.\n2. Deactive that group of virus.\n3. Let the rest group of virus spread.\nWe could use dfs to implement 1, 2, and 3. \nThe trickest p...
1
0
['Depth-First Search', 'Simulation']
0
contain-virus
Infinite Grid? DSU & DFS [Modular w/ Diagram]
infinite-grid-dsu-dfs-modular-w-diagram-marfe
General Idea\n\n- If the board is huge, we\'d want to avoid traverse it every time to process everything. \n [My solution will work even if the grid is infinit
Student2091
NORMAL
2022-06-19T09:26:37.752003+00:00
2022-06-22T07:09:53.760126+00:00
510
false
**General Idea**\n\n- If the board is huge, we\'d want to avoid traverse it every time to process everything. \n *[My solution will work even if the grid is infinitely large as long as we are given a list of virus coordinates.]*\n\n- There is a way to do that - *Union Find* - we can traverse the board 1 time to get al...
1
0
['Java']
0
contain-virus
C++| DFS+DSU
c-dfsdsu-by-kumarabhi98-byin
\nclass Solution {\npublic:\n int n,m;\n int d[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};\n int find(vector<int>& nums,int i){\n if(nums[i]==-1) retur
kumarabhi98
NORMAL
2022-06-09T14:09:21.025934+00:00
2022-06-09T14:09:21.025967+00:00
549
false
```\nclass Solution {\npublic:\n int n,m;\n int d[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};\n int find(vector<int>& nums,int i){\n if(nums[i]==-1) return i;\n else return nums[i] = find(nums,nums[i]);\n }\n void union_(vector<int>& nums,int x,int y){\n int i = find(nums,x), j = find(nums,...
1
0
['Depth-First Search', 'C']
0
contain-virus
✅ C++ | CLEAN CODE | BFS
c-clean-code-bfs-by-akshitasinghal-7gpx
\nclass Solution {\npublic:\n int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};\n int walls=0;\n \n bool isValid(int i,int j,int m,int n,vector<vector<int>> &v
akshitasinghal
NORMAL
2022-03-25T10:53:38.038563+00:00
2022-03-25T10:53:38.038602+00:00
852
false
```\nclass Solution {\npublic:\n int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};\n int walls=0;\n \n bool isValid(int i,int j,int m,int n,vector<vector<int>> &vis)\n {\n return (i>=0 && i<m && j>=0 && j<n && !vis[i][j]); \n }\n \n int find(int i,int j,int m,int n,vector<vector<int>>& a)\n {\n ...
1
0
['Breadth-First Search', 'C', 'C++']
1
contain-virus
Unable to find issue in code. Failing test case added
unable-to-find-issue-in-code-failing-tes-jzen
\nclass Solution {\n public int containVirus(int[][] isInfected) {\n int m = isInfected.length;\n int n = isInfected[0].length;\n int[]
akshay82
NORMAL
2022-03-02T02:27:14.728566+00:00
2022-03-02T02:27:14.728593+00:00
116
false
```\nclass Solution {\n public int containVirus(int[][] isInfected) {\n int m = isInfected.length;\n int n = isInfected[0].length;\n int[] dx = {0, 0, 1, -1};\n int[] dy = {1, -1, 0, 0};\n int total = 0;\n int count = 0;\n int maxWalls = 0;\n print(isInfected, ...
1
0
[]
0
contain-virus
C++ DFS solution, Easy Understand.
c-dfs-solution-easy-understand-by-dxw199-c2rg
```c++\nclass Solution {\n \n int M, N;\n \n //marking those cells as -1\n void buildWall(vector>& fec, int r, int c){\n //if it is alread
dxw1997
NORMAL
2021-11-01T11:09:58.263523+00:00
2021-11-01T11:09:58.263562+00:00
575
false
```c++\nclass Solution {\n \n int M, N;\n \n //marking those cells as -1\n void buildWall(vector<vector<int>>& fec, int r, int c){\n //if it is already marked or empty, just return.\n if(r < 0 || c < 0 || r >= M || c >= N || fec[r][c] <= 0) return;\n fec[r][c] = -1;//mark this cell.\...
1
0
[]
0
contain-virus
java no brain approach
java-no-brain-approach-by-jjyz-9mdu
```\nclass Solution {\n class Info{\n int wallsToBuild;\n Set threatenArea;\n Set origArea;\n public Info(int x, Set threatenArea
JJYZ
NORMAL
2020-08-03T03:13:32.981959+00:00
2020-08-03T03:13:32.982007+00:00
497
false
```\nclass Solution {\n class Info{\n int wallsToBuild;\n Set<Integer> threatenArea;\n Set<Integer> origArea;\n public Info(int x, Set<Integer> threatenArea, Set<Integer> origArea){\n this.wallsToBuild = x;\n this.threatenArea = threatenArea;\n this.origAr...
1
0
[]
0
contain-virus
Straight Forward Python Solution
straight-forward-python-solution-by-zlar-yofk
\nclass Solution:\n def containVirus(self, grid: List[List[int]]) -> int:\n\n rows, cols = len(grid), len(grid[0])\n\n def adj_cells(row, col):
zlareb1
NORMAL
2020-05-17T12:58:04.181767+00:00
2020-05-17T12:58:04.181817+00:00
905
false
```\nclass Solution:\n def containVirus(self, grid: List[List[int]]) -> int:\n\n rows, cols = len(grid), len(grid[0])\n\n def adj_cells(row, col):\n for r, c in [\n (row + 1, col),\n (row - 1, col),\n (row, col + 1),\n (row, col - 1...
1
0
['Breadth-First Search', 'Python3']
0
contain-virus
Accepted C# Solution with Union-Find
accepted-c-solution-with-union-find-by-m-jy2f
\n public class Solution\n {\n private static readonly (int di, int dj)[] _directions = { (0, 1), (0, -1), (1, 0), (-1, 0) };\n\n private cl
maxpushkarev
NORMAL
2020-03-20T09:43:19.634134+00:00
2020-03-20T09:43:19.634168+00:00
281
false
```\n public class Solution\n {\n private static readonly (int di, int dj)[] _directions = { (0, 1), (0, -1), (1, 0), (-1, 0) };\n\n private class Unions\n {\n private readonly int[] _parents;\n private readonly int[] _ranks;\n\n public Unions(int n)\n ...
1
0
['Union Find']
0
contain-virus
cell contained python bfs
cell-contained-python-bfs-by-je390-ln1q
0: is a free cell\n1: is a contaminated cell that is spreading\n-1: is a contaminated cell that we stopped spreading\n\nfor each connected component of 1s\n1. a
je390
NORMAL
2020-01-07T02:35:18.621254+00:00
2020-01-07T02:35:18.621304+00:00
219
false
0: is a free cell\n1: is a contaminated cell that is spreading\n-1: is a contaminated cell that we stopped spreading\n\nfor each connected component of 1s\n1. a hashset of all the connected cells under this same connected component\n2. the number of walls it would take to quarantine this cc\n3. the number of cells it w...
1
0
[]
1
contain-virus
[C++] 4ms DFS beats 100%
c-4ms-dfs-beats-100-by-whoisnoone-vg4s
\npublic:\n int containVirus(vector<vector<int>>& grid) {\n while (build_wall(grid)) {}\n return res;\n }\n \nprivate:\n int res = 0;\
whoisnoone
NORMAL
2019-10-15T04:28:26.991662+00:00
2019-10-15T04:39:43.577034+00:00
420
false
```\npublic:\n int containVirus(vector<vector<int>>& grid) {\n while (build_wall(grid)) {}\n return res;\n }\n \nprivate:\n int res = 0;\n int dfs(vector<vector<int>>& grid, int i, int j, int k, int& wall, vector<vector<int>>& infected_grid) {\n if (i < 0 || i >= grid.size() || j < 0...
1
0
[]
0
contain-virus
Simple Java DFS
simple-java-dfs-by-a_love_r-w8vn
~~~java\n\nclass Solution {\n int m, n;\n int[] dx = new int[]{1,-1,0,0};\n int[] dy = new int[]{0,0,1,-1};\n \n boolean[][] visited;\n List>
a_love_r
NORMAL
2019-07-23T02:28:31.272142+00:00
2019-07-23T02:28:31.272172+00:00
472
false
~~~java\n\nclass Solution {\n int m, n;\n int[] dx = new int[]{1,-1,0,0};\n int[] dy = new int[]{0,0,1,-1};\n \n boolean[][] visited;\n List<Set<Integer>> region;\n List<Set<Integer>> frontier;\n List<Integer> perimeter;\n \n public int containVirus(int[][] grid) {\n m = grid.length...
1
0
[]
2
contain-virus
Simulation with Union-Find (C++, 12ms)
simulation-with-union-find-c-12ms-by-las-4z50
This is a straight forward solution without any algorithmic tricks. I applied union-find here instead of DFS. Code is clear enough to understand. \nC++\nclass S
laseinefirenze
NORMAL
2018-11-08T07:02:02.155605+00:00
2018-11-08T07:02:02.155647+00:00
403
false
This is a straight forward solution without any algorithmic tricks. I applied union-find here instead of DFS. Code is clear enough to understand. \n```C++\nclass Solution {\n int M, N, K;\n vector<int> root, affect;\n \n // operations of Union-Find\n int find_root(int i) {\n if (root[i] == -1) ret...
1
0
[]
0
contain-virus
Java DFS beats 88% as of 10/21/18
java-dfs-beats-88-as-of-102118-by-mach7-xwad
``` class Solution { static int[] dir = {-1, 0, 1, 0, -1}; public int containVirus(int[][] grid) { if (grid == null || grid.length == 0 || grid[0].length ==
mach7
NORMAL
2018-10-21T07:38:03.167515+00:00
2018-10-21T07:38:03.167577+00:00
468
false
``` class Solution { static int[] dir = {-1, 0, 1, 0, -1}; public int containVirus(int[][] grid) { if (grid == null || grid.length == 0 || grid[0].length == 0) return 0; int m = grid.length, n = grid[0].length, target = 0, walls = 0; for (int[] row: grid) { for (int...
1
0
[]
0
contain-virus
Java Union Find Solution. Simulate the evolution.
java-union-find-solution-simulate-the-ev-gx9e
Just provide another way to solve the problem. Although the code is lengthy, but the idea is simple and commented inline. \n\nclass Solution {\n public int c
crazy_y
NORMAL
2018-01-10T09:19:28.328000+00:00
2018-01-10T09:19:28.328000+00:00
277
false
Just provide another way to solve the problem. Although the code is lengthy, but the idea is simple and commented inline. \n```\nclass Solution {\n public int containVirus(int[][] grid) {\n int rst = 0;\n int s = solve(grid);\n while (s != 0) {\n rst += s;\n s = solve(grid)...
1
0
[]
0
contain-virus
My ugly java DFS solution 19 ms with explaination
my-ugly-java-dfs-solution-19-ms-with-exp-aiab
The test case 3 is wrong. It should be 13 instead of 11.\nThe idea is to use dfs for each group of virus to find out how many cells will be infected and how man
jinsheng
NORMAL
2017-12-17T04:13:37.845000+00:00
2017-12-17T04:13:37.845000+00:00
943
false
The test case 3 is wrong. It should be 13 instead of 11.\nThe idea is to use dfs for each group of virus to find out how many cells will be infected and how many walls will be needed. If an adjacent good cells has been visited, next time it is reached by dfs, the count for walls still need to increase 1.\nThen we selec...
1
0
[]
0
contain-virus
[749. Contain Virus] C++_AC_16ms_DFS
749-contain-virus-c_ac_16ms_dfs-by-jason-8zbx
Pretty straightforward problem, by using DFS and following the requirements of this problem.\n\n class Solution {\n public:\n int containVirus(vector>&
jasonshieh
NORMAL
2017-12-17T20:44:54.753000+00:00
2017-12-17T20:44:54.753000+00:00
449
false
Pretty straightforward problem, by using DFS and following the requirements of this problem.\n\n class Solution {\n public:\n int containVirus(vector<vector<int>>& grid) {\n if(grid.empty()) return 0;\n int m = grid.size();\n int n = grid[0].size();\n int res = 0;\n //The num...
1
0
[]
0
contain-virus
Naive C++ solution using BFS
naive-c-solution-using-bfs-by-frank_fan-xmaz
Just follow the instruction of the problem. You can run it to see the output of every stage. Hope to find a more elegant algorithm.\n\nclass Solution {\npublic:
frank_fan
NORMAL
2017-12-17T04:04:22.581000+00:00
2017-12-17T04:04:22.581000+00:00
927
false
Just follow the instruction of the problem. You can run it to see the output of every stage. Hope to find a more elegant algorithm.\n```\nclass Solution {\npublic:\n int containVirus(vector<vector<int>>& grid) {\n size_t row = grid.size(), col = grid[0].size();\n int dirs[4][2] = {{1, 0}, {-1, 0}, {0, ...
1
0
[]
4
contain-virus
Explained solution 4ms
explained-solution-7ms-by-aviadblumen-wzlx
Code
aviadblumen
NORMAL
2025-03-27T13:13:34.603237+00:00
2025-03-27T13:14:37.794385+00:00
6
false
![image.png](https://assets.leetcode.com/users/images/bfda097f-f02c-48dd-97c6-b11ab2ca9158_1743081265.7291005.png) # Code ```cpp [] class Solution { int m,n; public: void spread_to_neighbors(vector<vector<int>>& board, int r, int c,int prev_marker, int marker){ // skip out of border and blocked cells...
0
0
['C++']
0
contain-virus
C++ | Simple DFS Solution
c-simple-dfs-solution-by-kena7-0fwv
Code
kenA7
NORMAL
2025-03-18T14:16:58.393645+00:00
2025-03-18T14:16:58.393645+00:00
8
false
# Code ```cpp [] class Solution { int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int m,n; bool isValidMove(int x, int y) { return x>=0 && y>=0 && x<m && y<n; } void dfs(int i,int j, vector<vector<int>>& g, set<pair<int,int>> &st) { g[i][j]=-1; // Mark as visited //Mov...
0
0
['C++']
0
contain-virus
Ultra-Fast Virus Containment Algorithm - Optimized DFS with 1D indexing
ultra-fast-virus-containment-algorithm-o-cdnk
IntuitionApproachComplexity Time complexity: Space complexity: Code
Baltazin
NORMAL
2025-03-14T12:11:17.901596+00:00
2025-03-14T12:11:17.901596+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C#']
0
contain-virus
Lengthy But Simple Java Solution
lengthy-but-simple-java-solution-by-deco-9rub
IntuitionThe solution is simple. We need to keep doing dfs/bfs until and unless all the infection is spread or blocked.ApproachKeep track of infected nodes and
decodificar_e
NORMAL
2025-02-05T20:14:16.134051+00:00
2025-02-05T20:14:16.134051+00:00
8
false
# Intuition The solution is simple. We need to keep doing dfs/bfs until and unless all the infection is spread or blocked. # Approach Keep track of infected nodes and non infected nodes through bfs/dfs at each step. This will let us know which island of nodes to close such infection is minimal. # Complexity - Time co...
0
0
['Java']
0
contain-virus
C++ Easy Solution
c-easy-solution-by-harishnandre-tnhn
Code
harishnandre
NORMAL
2025-01-30T19:47:18.826590+00:00
2025-01-30T19:47:18.826590+00:00
25
false
# Code ```cpp [] class Solution { public: vector<int> del = {-1, 0, 1, 0}; void dfs(int i, int j, vector<vector<int>>& isInfected, vector<vector<int>>& vis, vector<int>& eachComp, int n, int m) { vis[i][j] = 1; int node = i * m + j; eachComp.push_back(node); for (int k = 0; k ...
0
0
['Depth-First Search', 'Matrix', 'C++']
0
contain-virus
749. Contain Virus
749-contain-virus-by-g8xd0qpqty-6d1b
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2024-12-29T08:10:13.264770+00:00
2024-12-29T08:10:13.264770+00:00
15
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
contain-virus
JavaScript | Simple Solution Written for Clarity
javascript-simple-solution-written-for-c-i4pi
null
Faheem-maker
NORMAL
2024-12-12T03:40:34.626044+00:00
2024-12-12T03:40:34.626044+00:00
6
false
# Intuition\nIn order to solve the problem, we are going to simulate the exact process. In code, the idea\'s as simple as writing this loop:\n```javascript\nvar result = 0;\n\nlet tmp = 0;\n\ndo {\n tmp = contain(isInfected);\n result += tmp;\n spread(isInfected);\n} while (tmp != 0);\n\nreturn result;\n```\nT...
0
0
['Depth-First Search', 'Graph', 'Matrix', 'JavaScript']
0
contain-virus
Python (Simple BFS)
python-simple-bfs-by-rnotappl-g4wz
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
rnotappl
NORMAL
2024-11-25T07:59:46.680925+00:00
2024-11-25T07:59:46.680963+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
contain-virus
using disjoint union
using-disjoint-union-by-arpanbiswas1812-u191
\n\n# Code\ncpp []\nclass Solution {\npublic:\n int Uparent(int u,vector<int>& parent){\n if(u==parent[u])\n return u;\n return pare
arpanbiswas1812
NORMAL
2024-11-14T13:31:24.096118+00:00
2024-11-14T13:31:24.096141+00:00
12
false
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n int Uparent(int u,vector<int>& parent){\n if(u==parent[u])\n return u;\n return parent[u]=Uparent(parent[u],parent);\n }\n void union_disjoint(int u,int v,vector<int>& parent,vector<int>& size){\n int pu=Uparent(u,parent);\n ...
0
0
['C++']
0
contain-virus
easiest solution by NIKHIL DWIVEDI
easiest-solution-by-nikhil-dwivedi-by-nd-ubv2
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach: Key Concepts\nThe solution revolves around several key concepts:\n\nGrid
ND200499
NORMAL
2024-11-10T11:31:57.434374+00:00
2024-11-10T11:31:57.434429+00:00
21
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach: Key Concepts\nThe solution revolves around several key concepts:\n\nGrid Representation: The grid is represented as a 2D array where:\n\n0 indicates an uninfected cell,\n1 indicates an infected cell,\n2 indicates a cell that...
0
0
['Java']
0
contain-virus
readable iterative dfs solution beats 95%
readable-iterative-dfs-solution-beats-95-lzee
Intuition\n Describe your first thoughts on how to solve this problem. \nDivide problem into subproblems, create functions for each subproblem\nput these functi
hknakbiyik10
NORMAL
2024-10-24T21:58:37.462475+00:00
2024-10-24T21:58:37.462501+00:00
56
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDivide problem into subproblems, create functions for each subproblem\nput these functions in global scope so that code is readable\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nkeep track of freezed cells (exclu...
0
0
['Array', 'Depth-First Search', 'Matrix', 'Simulation', 'Python3']
1
contain-virus
C++ | dfs
c-dfs-by-notsojay-rg4z
Complexity\n- Time complexity: O((m * n)^2)\n\n- Space complexity: O(m * n)\n\n# Code\ncpp []\nclass Solution {\n struct RegionInfo {\n std::set<std::
notsojay
NORMAL
2024-10-21T06:13:46.616338+00:00
2024-10-21T09:19:23.280507+00:00
18
false
# Complexity\n- Time complexity: O((m * n)^2)\n\n- Space complexity: O(m * n)\n\n# Code\n```cpp []\nclass Solution {\n struct RegionInfo {\n std::set<std::pair<int, int>> threat;\n std::set<std::pair<int, int>> infectedCells;\n int wallsNeeded;\n RegionInfo() : wallsNeeded(0) {}\n };\n...
0
0
['Depth-First Search', 'Graph', 'Recursion', 'Matrix', 'C++']
0
contain-virus
[DFS][Python] time beats 100% solutions
dfspython-time-beats-100-solutions-by-vi-yyq1
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. check the district w
vikotse
NORMAL
2024-10-17T15:39:30.213365+00:00
2024-10-17T15:39:30.213400+00:00
9
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. check the district which would be diffused.\n2. build the wall by the information from 1.\n3. diffusing for current districts.\n\n# Complexity\n- Time complexity:\n...
0
0
['Python3']
0
contain-virus
Beats 0 %
beats-0-by-stack_exchange-dpzt
Intuition\nThe goal of the problem is to contain a viral outbreak on a grid by building walls around the most threatening regions. The algorithm needs to identi
Stack_Exchange
NORMAL
2024-10-01T10:55:25.766805+00:00
2024-10-01T10:55:25.766828+00:00
7
false
### Intuition\nThe goal of the problem is to contain a viral outbreak on a grid by building walls around the most threatening regions. The algorithm needs to identify these regions, calculate how many walls are required to contain them, and then process the spread of the infection accordingly.\n\n### Approach\n1. **Ide...
0
0
['C++']
0
contain-virus
749. Contain Virus
749-contain-virus-by-mimiseksimi-qji5
Intuition\nThe problem requires simulating the spread of a virus and containment efforts day by day. We need to identify the region that threatens the most unin
mimiseksimi
NORMAL
2024-09-06T14:43:54.923587+00:00
2024-09-06T14:43:54.923624+00:00
9
false
# Intuition\nThe problem requires simulating the spread of a virus and containment efforts day by day. We need to identify the region that threatens the most uninfected cells each day, quarantine it, and continue this process until all infected regions are contained or the entire grid is infected.\n\n# Approach\n1. Imp...
0
0
['Python3']
0
contain-virus
Simulation - BFS
simulation-bfs-by-a4yan1-q4ch
Code\ncpp []\nclass Solution {\npublic:\n int drow[4] = {-1,0,1,0};\n int dcol[4] = {0,1,0,-1};\n int no_of_cells_infected(vector<vector<int>> &grid,in
a4yan1
NORMAL
2024-09-06T05:31:31.624142+00:00
2024-09-06T05:31:31.624181+00:00
6
false
# Code\n```cpp []\nclass Solution {\npublic:\n int drow[4] = {-1,0,1,0};\n int dcol[4] = {0,1,0,-1};\n int no_of_cells_infected(vector<vector<int>> &grid,int row,int col,vector<vector<int>> &vis,vector<vector<int>> &already){\n vis[row][col] = 1;\n queue<pair<int,int>> q;\n q.push({row,col...
0
0
['Breadth-First Search', 'Matrix', 'Simulation', 'C++']
0
contain-virus
Swift - Contain Virus
swift-contain-virus-by-ksmirnovnn-vn5g
\n\nclass Solution {\n func containVirus(_ isInfected: [[Int]]) -> Int {\n // Copy of the original grid to modify during processing\n var grid
ksmirnovnn
NORMAL
2024-07-18T19:35:33.298379+00:00
2024-07-18T19:35:33.298398+00:00
3
false
\n```\nclass Solution {\n func containVirus(_ isInfected: [[Int]]) -> Int {\n // Copy of the original grid to modify during processing\n var grid = isInfected\n // Directions for moving up, down, left, and right\n let directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n // Variable to...
0
0
['Swift']
0
contain-virus
Simple DFS based component counting + Implementation skills
simple-dfs-based-component-counting-impl-gol2
Intuition\nSimple DFS based component counting + Implementation skills.\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ashutoshdayal
NORMAL
2024-06-05T10:44:10.395724+00:00
2024-06-05T10:44:10.395747+00:00
56
false
# Intuition\nSimple DFS based component counting + Implementation skills.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# ...
0
0
['C++']
0
contain-virus
good
good-by-gjwlsgur4866-3w22
Approach\n1. dfs -> \uBAA8\uB4E0 \uBC14\uC774\uB7EC\uC2A4 \uC9C0\uC5ED, \uADF8 \uC9C0\uC5ED\uC774 \uBBF8\uCE58\uB294 \uC704\uD611, \uACA9\uB9AC\uD558\uB294 \uB3
gjwlsgur4866
NORMAL
2024-05-29T01:03:55.409762+00:00
2024-05-29T01:03:55.409780+00:00
28
false
# Approach\n1. dfs -> \uBAA8\uB4E0 \uBC14\uC774\uB7EC\uC2A4 \uC9C0\uC5ED, \uADF8 \uC9C0\uC5ED\uC774 \uBBF8\uCE58\uB294 \uC704\uD611, \uACA9\uB9AC\uD558\uB294 \uB370 \uD544\uC694\uD55C \uBCBD\uC758 \uC218\n2. \uC704\uD611 \uAC00\uC7A5 \uD070 \uACF3 \uACA9\uB9AC = \uBCBD \uC138\uC6B0\uAE30 -> isInfected[i][j] = -1\n3. \u...
0
0
['Simulation', 'Java']
0
contain-virus
Python Hard
python-hard-by-lucasschnee-aavm
\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n M, N = len(isInfected), len(isInfected[0])\n directions = [(0
lucasschnee
NORMAL
2024-05-23T03:31:47.747117+00:00
2024-05-23T03:31:47.747160+00:00
12
false
```\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n M, N = len(isInfected), len(isInfected[0])\n directions = [(0, 1), (0, -1), (-1, 0), (1, 0)]\n marked = defaultdict(set)\n walls = 0\n\n def bfs(x, y):\n q = deque([(x, y)])\n ...
0
0
['Python3']
0
contain-virus
Python BFS Clean Approach (beats 100% solutions)
python-bfs-clean-approach-beats-100-solu-lg0z
\n Describe your approach to solving the problem. \n\n# Approach\n\n- Identify Separate Regions: Identify all infected regions and their respective boundaries.\
codedoctor
NORMAL
2024-05-18T21:22:05.613168+00:00
2024-05-18T21:22:05.613194+00:00
4
false
\n<!-- Describe your approach to solving the problem. -->\n\n# Approach\n\n- Identify Separate Regions: Identify all infected regions and their respective boundaries.\n\n- Prioritize by Threat: Determine which region poses the greatest threat by the number of uninfected cells it can potentially infect.\n\n- Contain the...
0
0
['Python']
0
contain-virus
BEST C++ SOLUTION WITH 41MS OF RUNTIME !
best-c-solution-with-41ms-of-runtime-by-fag4c
\n# Code\n\nstruct Region {\n // Given m = the number of rows and n = the number of columns, (x, y) will be\n // hashed as x * n + y.\n unordered_set<int> in
rishabnotfound
NORMAL
2024-04-23T06:55:59.744725+00:00
2024-04-23T06:55:59.744748+00:00
38
false
\n# Code\n```\nstruct Region {\n // Given m = the number of rows and n = the number of columns, (x, y) will be\n // hashed as x * n + y.\n unordered_set<int> infected;\n unordered_set<int> noninfected;\n int wallsRequired = 0;\n};\n\nclass Solution {\n public:\n int containVirus(vector<vector<int>>& isInfected) {...
0
0
['C++']
0
contain-virus
[CPP] Clean Code for Interviews
cpp-clean-code-for-interviews-by-tr1ten-ujof
\n\n# Code\n\n\n\nstruct Region {\n unordered_set<int> inf;\n unordered_set<int> non_inf;\n int walls;\n};\nbool operator<(const Region &r,const Region
tr1ten
NORMAL
2024-04-21T06:16:42.301856+00:00
2024-04-21T06:16:42.301893+00:00
54
false
\n\n# Code\n```\n\n\nstruct Region {\n unordered_set<int> inf;\n unordered_set<int> non_inf;\n int walls;\n};\nbool operator<(const Region &r,const Region &b){\n return r.non_inf.size() < b.non_inf.size();\n}\n\nclass Solution {\npublic:\n vector<Region> regions; \n vector<vector<int>> mat;\n vec...
0
0
['C++']
0
contain-virus
straightforward solution w/ detailed comments
straightforward-solution-w-detailed-comm-cboc
Code\n\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n if all(cell == 0 for row in isInfected for cell in row): retur
jyscao
NORMAL
2024-04-14T20:26:39.806370+00:00
2024-04-14T20:39:27.885830+00:00
14
false
# Code\n```\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n if all(cell == 0 for row in isInfected for cell in row): return 0\n\n m, n = len(isInfected), len(isInfected[0])\n\n # neighbors of a cell are those that are 4-directionally adjacent w/o going out of bou...
0
0
['Depth-First Search', 'Graph', 'Matrix', 'Python3']
0
contain-virus
DFS
dfs-by-kaicool9789-sc2s
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
kaicool9789
NORMAL
2024-04-13T08:00:37.727676+00:00
2024-04-13T08:00:37.727706+00:00
23
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Depth-First Search', 'C++']
0
contain-virus
DFS + heap
dfs-heap-by-ynnekuw-kaoj
Intuition\n Describe your first thoughts on how to solve this problem. \n\nPython version of this.\n\n# Code\npython\nfrom heapq import heappush\n\nclass Cluste
ynnekuw
NORMAL
2024-03-26T07:00:37.136258+00:00
2024-03-26T07:00:37.136283+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nPython version of [this](https://leetcode.com/problems/contain-virus/solutions/847507/cpp-dfs-solution-explained).\n\n# Code\n```python\nfrom heapq import heappush\n\nclass Cluster:\n def __init__(self):\n self.wall_cnt = 0\n ...
0
0
['Python3']
0
contain-virus
Python - DFS + Dictionary Method
python-dfs-dictionary-method-by-kondrago-5zhf
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
KonDrago
NORMAL
2024-02-28T05:04:45.400405+00:00
2024-02-28T05:08:45.117695+00:00
11
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
contain-virus
✅ Easy BFS solution | Python
easy-bfs-solution-python-by-anujmah-ntzt
Code\n\nfrom collections import deque\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n rows = len(isInfected)\n
anujmah
NORMAL
2024-02-24T20:16:43.344195+00:00
2024-02-24T20:16:43.344227+00:00
43
false
# Code\n```\nfrom collections import deque\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n rows = len(isInfected)\n col = len(isInfected[0])\n\n # get all the contaminated cells present using BFS\n def getContaminatedArea():\n infectedAreas = []...
0
0
['Array', 'Breadth-First Search', 'Matrix', 'Simulation', 'Python3']
0
contain-virus
O(nm α(nm)) ≈ O(nm) || Python Solution || Union-Find
onm-anm-onm-python-solution-union-find-b-pwqb
\nclass DisjointSet:\n def __init__(self, iterable):\n self.parent = {}\n self.rank = {}\n\n for x in iterable:\n self.make_s
tom7em
NORMAL
2024-02-19T11:11:35.832766+00:00
2024-02-19T11:11:35.832794+00:00
13
false
```\nclass DisjointSet:\n def __init__(self, iterable):\n self.parent = {}\n self.rank = {}\n\n for x in iterable:\n self.make_set(x)\n\n def __contains__(self, x):\n return x in self.parent\n\n def make_set(self, x):\n self.parent[x] = x\n self.rank[x] = 0\...
0
0
['Python3']
0
contain-virus
JS || Solution by Bharadwaj
js-solution-by-bharadwaj-by-manu-bharadw-5lqt
Code\n\nclass CircularQueue {\n\n constructor(capacity) {\n\n this._capacity = capacity;\n\n this._size = 0;\n\n this._bottom = 0;\n\n
Manu-Bharadwaj-BN
NORMAL
2024-02-07T06:06:04.667019+00:00
2024-02-07T06:06:04.667037+00:00
13
false
# Code\n```\nclass CircularQueue {\n\n constructor(capacity) {\n\n this._capacity = capacity;\n\n this._size = 0;\n\n this._bottom = 0;\n\n this._data = Array(capacity).fill(undefined);\n }\n\n _getCircularIndex(index) {\n const result = index % this._capacity;\n if (r...
0
0
['JavaScript']
0
contain-virus
TS solution
ts-solution-by-gennadysx-0hlb
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
GennadySX
NORMAL
2024-01-15T23:25:06.079685+00:00
2024-01-15T23:25:06.079703+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['TypeScript']
0
contain-virus
749. Contain Virus.cpp
749-contain-viruscpp-by-202021ganesh-8bjo
Code\n\nclass Solution {\npublic:\n int containVirus(vector<vector<int>>& grid) {\n int ans = 0;\n while (true) {\n int walls = mode
202021ganesh
NORMAL
2024-01-10T16:25:51.565552+00:00
2024-01-10T16:25:51.565594+00:00
8
false
**Code**\n```\nclass Solution {\npublic:\n int containVirus(vector<vector<int>>& grid) {\n int ans = 0;\n while (true) {\n int walls = model(grid);\n if (walls == 0) break;\n ans += walls;\n }\n return ans;\n }\nprivate:\n int model(vector<vector<int...
0
0
['C']
0
contain-virus
python
python-by-susmita2004-ng16
\n\n# Code\n\nclass Solution:\n def containVirus(self, mat: List[List[int]]) -> int:\n m, n = len(mat), len(mat[0])\n DIRECTIONS = [(-1, 0), (1
susmita2004
NORMAL
2023-12-30T16:37:48.492017+00:00
2023-12-30T16:37:48.492044+00:00
6
false
\n\n# Code\n```\nclass Solution:\n def containVirus(self, mat: List[List[int]]) -> int:\n m, n = len(mat), len(mat[0])\n DIRECTIONS = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n \n def dfs(i, j, visited):\n if not (0 <= i < m and 0 <= j < n) or (i, j) in visited:\n retu...
0
0
['Python3']
0
contain-virus
Simulation using easy to follow code
simulation-using-easy-to-follow-code-by-rd6oc
Intuition\nSimulate the virus containment and spreading in a clear\nand easy to understand way. \n\n# Approach\nSimulates each tick of the containment and infec
grangej
NORMAL
2023-12-04T22:34:50.067469+00:00
2023-12-04T22:34:50.067497+00:00
12
false
# Intuition\nSimulate the virus containment and spreading in a clear\nand easy to understand way. \n\n# Approach\nSimulates each tick of the containment and infection, while tracking the virus that are not contained.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space c...
0
0
['Swift']
0
contain-virus
Using BFS
using-bfs-by-daminibansal1725-pj51
Code\n\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n dirs = [(1, 0), (-1, 0), (0, 1), (0, -1)]\n m, n = len(
daminibansal1725
NORMAL
2023-10-24T07:38:51.803214+00:00
2023-10-24T07:38:51.803232+00:00
27
false
# Code\n```\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n dirs = [(1, 0), (-1, 0), (0, 1), (0, -1)]\n m, n = len(isInfected), len(isInfected[0])\n ans = 0\n while True:\n # 1. BFS\n # neighbors stores every to-spread/to-put-wall a...
0
0
['Python3']
0
contain-virus
copy paste
copy-paste-by-shivamkhandare03-chvp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
shivamkhandare03
NORMAL
2023-10-23T07:11:30.699409+00:00
2023-10-23T07:11:30.699437+00:00
29
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0