id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool recPartitioning(vector<int> &nums, int totalSum, unordered_map<string, bool> &mp, int i ) {\n string s = to_string(i) + to_string(totalSum);\n if(mp.find(s)!= mp.end()) return mp[s];\n if(totalSum == 0) return true;\n if(totalSum < 0 || i == nums.... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "const static auto _ = [] { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return nullptr; }();\n\nclass Solution {\npublic:\n bool recPartitioning(vector<int> &nums, int totalSum, unordered_map<string, bool> &mp, int i ) {\n string s = to_string(i) + to_string(tota... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int sum = 0;\n int n = nums.size();\n for (int i = 0; i < n; ++i) {\n sum += nums[i];\n }\n if (sum % 2 != 0)\n return false;\n\n int target = sum / 2;\n unordered_... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n \n int n = nums.size();\n int sum = 0;\n for(int i = 0; i < n; i++){\n sum += nums[i];\n }\n if(sum % 2){\n return false;\n }\n sum = sum / 2;\n unord... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int sum = 0;\n for(auto n:nums) {\n sum += n;\n }\n if((sum%2)==1) return false;\n\n unordered_set<int> dp;\n dp.insert(0);\n int target = sum/2;\n\n for(int i=nums.siz... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int sum = 0;\n for(auto n:nums) {\n sum += n;\n }\n if((sum%2)==1) return false;\n\n unordered_set<int> dp;\n dp.insert(0);\n int target = sum/2;\n\n for(int i=nums.siz... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n int n;\n unordered_map<string, bool> memo;\n bool canPartition(vector<int>& nums) { //main logic: a subset with a sum equal to half the sum of the entire array.\n n = nums.size();\n int sum = 0;\n for(int num : nums) {sum += num;}\n if (sum %... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "const static auto _ = [] { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return nullptr; }();\n\nclass Solution {\npublic:\n bool recPartitioning(vector<int> &nums, int totalSum, unordered_map<string, bool> &mp, int i ) {\n string s = to_string(i) +'_'+ to_string(... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int sum = accumulate(nums.begin(), nums.end(), 0);\n if (sum % 2) {\n return false;\n }\n unordered_set<int> reachable;\n reachable.insert(0);\n for (int i = 0; i < nums.size(); i++)... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int total = accumulate(nums.begin(), nums.end(), 0);\n if (total % 2)\n return false;\n\n total /= 2;\n unordered_set<int> dp = {0};\n for (auto& n : nums) {\n unordered_set<int>... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int sum=accumulate(nums.begin(), nums.end(), 0);\n if(sum%2) return false;\n unordered_set<int> s;\n s.insert(0);\n for(int i=nums.size()-1; i>-1; --i){\n unordered_set<int> t=s;\n ... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n // dp\n // observe: both halfs have to equal HALF of the total sum\n // if total sum is odd, return false\n // bottom up: start at back and add up sums\n // if one sum equals target, return tr... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n // if(nums.size() == 1)\n // return false;\n const int sum = accumulate(nums.begin(),nums.end(),0);\n if(sum % 2 != 0)\n return false;\n const int tgt = sum/2;\n unordered_set<in... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "class Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n const int sum = accumulate(nums.begin(),nums.end(),0);\n if(sum % 2 != 0)\n return false;\n const int tgt = sum/2;\n unordered_set<int> s;\n s.insert(0);\n for(const auto v:nums) {\n... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "#include <vector>\n#include <numeric>\n#include <unordered_set>\n\nclass Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int total = std::accumulate(nums.begin(), nums.end(), 0);\n if (total % 2 != 0) {\n return false;\n }\n int target = total / 2;\n... |
416 | <p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:<... | 3 | {
"code": "#include <vector>\n#include <numeric>\n#include <unordered_set>\n\nclass Solution {\npublic:\n bool canPartition(vector<int>& nums) {\n int total = std::accumulate(nums.begin(), nums.end(), 0);\n if (total % 2 != 0) {\n return false;\n }\n int target = total / 2;\n... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n int x[4] = {1, -1, 0, 0};\n int y[4] = {0, 0, -1, 1};\n int vis[201][201]={0};\n int dp[201][201]={-1};\n int rec(int i, int j, int n, int m, vector<vector<int>>& heights){\n int ret = 0;\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n int x[4] = {1, -1, 0, 0};\n int y[4] = {0, 0, -1, 1};\n int vis[201][201]={0};\n int dp[201][201]={-1};\n int rec(int i, int j, int n, int m, vector<vector<int>>& heights){\n int ret = 0;\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n void bfs(std::deque<std::pair<int, int>>& q, std::vector<bool>& s, vector<vector<int>>& heights)\n {\n std::array<int, 5> const directions = { 0, 1, 0, -1, 0 };\n\n int const rows = heights.size();\n int const cols = heights[0].size(); \n\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);\n static set<pair<int, int>> check_set = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n vector<vector<uint8_t>> vis(heights... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>&grid) {\n int row=grid.size();\n int col=grid[0].size();\n vector<vector<bool>>atl(row,vector<bool>(col,0));\n vector<vector<bool>>pac(row,vector<bool>(col,0));\n for(int i=0;i<row;i++)... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:Solution(){\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n vector<vector<int>> pacificAtlantic(vector<vector<int>>&grid) {\n int row=grid.size();\n int col=grid[0].size();\n vector<vector<bool>>atl(row,vector<bool>... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(const vector<vector<int>>& heights) {\n const auto pcf = pacific(heights);\n const auto atl = atlantic(heights);\n vector<vector<int>> res;\n for(int r = 0; r < heights.size(); ++r) {\n for(int c = 0; ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\n int row, col;\n\n void bfs(queue<pair<int,int>>& q, vector<vector<bool>>& visited, vector<vector<int>>& heights) {\n int dx[] = {1, -1, 0, 0};\n int dy[] = {0, 0, 1, -1};\n\n while (!q.empty()) {\n auto [i,j] = q.front();\n q.pop();\n\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n \n /// main logic or trick for this problem : bahar se andar ki taraf jao\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n \n vector<vector<int>>ans;\n int m = heights.size();\n int n = heights[0].size();\n \n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 0 | {
"code": "class Solution {\npublic:\n void dfs(int i , int j , int r, int c, int prev, vector<vector<int>>& vis,vector<vector<int>>& heights){\n if ( i < 0 || j < 0 || i >=r || j >= c) return;\n if ( heights[i][j] < prev) return;\n if (vis[i][j]) return;\n\n vis[i][j] = 1;\n dfs... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n const int m = heights.size(), n = heights[0].size();\n vector<vector<int>> atl(m, vector<int>(n, 0));\n vector<vector<int>> pac(m, vector<int>(n, 0));\n for (int j = 0; j < n; j+... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m = heights.size();\n if (m == 0) return {};\n int n = heights[0].size();\n\n vector<vector<bool>> pacific(m, vector<bool>(n, false));\n vector<vector<bool>> atlantic(... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n// Directions for moving in the grid (right, down, left, up)\nint X[4] = {1, 0, -1, 0};\nint Y[4] = {0, 1, 0, -1};\n\n// BFS function to perform BFS from ocean edges\nvoid bfs(const vector<vector<int>>& heights, vector<vector<int>>& visited, queue<pair<int, int>>& q) {\n int r... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n vector<pair<int,int>>dir = {{0,1},{1,0},{0,-1},{-1,0}};\n int n,m;\n void bfs(queue<pair<int,int>>&q, vector<vector<int>>&vis, vector<vector<int>>& heights){\n while(!q.empty()){\n auto [x,y] = q.front();\n q.pop();\n for(auto [dx... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n\n const string PACIFIC_OCEAN = \"pacific\";\n const string ATLANTIC_OCEAN = \"atlantic\";\n \n bool checkVisited(string ocean, pair<int, int> p){\n if(ocean == ATLANTIC_OCEAN)\n return p.second == 1;\n return p.first == 1;\n }\n\n void ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n\n const string PACIFIC_OCEAN = \"pacific\";\n const string ATLANTIC_OCEAN = \"atlantic\";\n \n bool checkVisited(string ocean, pair<int, int> p){\n if(ocean == ATLANTIC_OCEAN)\n return p.second == 1;\n return p.first == 1;\n }\n\n void ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "//BFS\n//TC & SC : O(numRows*numCols)\n\nclass Solution { \npublic:\n// Directions for moving right, down, up, and left\n const vector<vector<int>> DIRECTIONS = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};\n int numRows;\n int numCols;\n vector<vector<int>> landHeights;\n \n\n vector<vector<int>... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir = {{1,0},{-1,0},{0,1},{0,-1}};\n int rows;\n int cols;\n vector<vector<int>> h;\n\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n rows = heights.size();\n cols = heights[0].size();\n h = heights;\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int n=heights.size();\n int m=heights[0].size();\n vector<vector<int>> vis(n,vector<int>(m,0));\n vector<vector<int>> vis2(n,vector<int>(m,0));\n queue<pair<int,int>> que;... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": " class Solution {\n public:\n void dfs(int i, int j,vector<vector<int>>& heights,unordered_set<int> &vis, int prevHeight)\n {\n int cellNumber = (i*heights[0].size()) + j;\n if(i < 0 || j < 0 || i >= heights.size() || j >= heights[0].size() || \n heights[i][... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\nvoid do_it(int t, vector<vector<int>> &res, queue<pair<int, int>> &q, vector<vector<int>> &visit, int n, int m, vector<vector<int>>& heights){\n while(!q.empty()){\n int i = q.front().first, j = q.front().second;\n q.pop();\n if(i-1 >= 0 && !visit[i-1][j] ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n void dfs(int row, int col, vector<vector<int>>& heights,\n vector<vector<int>>& ocean, vector<vector<int>>& vis) {\n vis[row][col] = 1;\n ocean[row][col] = 1;\n\n int n = heights.size();\n int m = heights[0].size();\n\n // Direct... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\n vector<vector<int>>a;\n int n,m;\npublic:\n vector<vector<int>> shared_n(vector<int>& x,vector<int>& y){\n vector<vector<int>>ans(n,vector<int>(m,0));\n for(int i=0;i<x.size();i++){\n ans[y[i]][x[i]]=1;\n }\n for(int i=0;i<x.size();i++){\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\n #define PACIFIC 1\n #define ATLANTIC 2\n #define BOTH (PACIFIC | ATLANTIC)\npublic:\n vector<vector<int>> pacificAtlantic(const vector<vector<int>>& heights) {\n int m = heights.size();\n int n = heights[0].size();\n vector<vector<int>> flows = vector<vec... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n\n void fill(vector<vector<int>>& heights, vector<vector<bool>> &dp, int x, int y){\n // cout << x << \" \" << y << \"\\n\";\n vector<pair<int, int>> neigh = {\n {x-1, y},\n {x, y-1},\n {x+1, y},\n {x, y+1}\n };\... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n bool isvalid( int row, int col,vector<vector<int>>& grid){\n if(row<0||row>=grid.size()) return false;\n if(col<0||col>=grid[0].size()) return false;\n return true;\n }\n \n int dr[4]={-1,0,1,0};\n int dc[4]={0,1,0,-1};\n void bfs(vector<vect... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(const vector<vector<int>>& heights) {\n const auto pcf = pacific(heights);\n const auto atl = atlantic(heights);\n vector<vector<int>> res;\n for(int r = 0; r < heights.size(); ++r) {\n for(int c = 0; ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\nprivate:\n void dfs(int r, int c, vector<vector<int>>& heights, vector<vector<bool>>& reachable) {\n int m = heights.size(), n = heights[0].size();\n reachable[r][c] = true;\n \n vector<pair<int, int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>& heights, vector<vector<int>>& vis1, stack<pair<pair<int, int>, int>>& st1){\n while(!st1.empty()){\n int x=st1.top().first.first;\n int y=st1.top().first.second;\n vis1[x][y]=1;\n int val=st1.top... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(const vector<vector<int>>& heights) {\n const auto pcf = pacific(heights);\n const auto atl = atlantic(heights);\n vector<vector<int>> res;\n for(size_t r = 0; r < heights.size(); ++r) {\n for(size_t c... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n if (heights.empty() || heights[0].empty()) return {};\n \n int m = heights.size();\n int n = heights[0].size();\n \n vector<vector<bool>> pacific(m, vector<bool>(n,... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n void dfs(int row, int col, set<pair<int, int>>& visited, vector<vector<int>>& heights, int prevHeight) {\n if(visited.count({row, col}) || row < 0 || col < 0 || row >= heights.size() || col >= heights[0].size() || heights[row][col] < prevHeight) {\n return;\... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n const vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {-1,0}, {0, -1}};\n\n void processHeights(deque<pair<int, int>>& to_visit,\n std::set<std::pair<int, int>>& can_flow,\n vector<vector<int>> heights, int n, int m,\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int ROWS = heights.size(), COLS = heights[0].size();\n unordered_set<int> pac, atl;\n\n for (int i = 0; i < ROWS; i++) {\n dfs(i, 0, pac, heights[i][0], ROWS, COLS, heights);... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int ROWS = heights.size(), COLS = heights[0].size();\n unordered_set<int> pac, atl;\n\n for (int i = 0; i < ROWS; i++) {\n dfs(i, 0, pac, heights[i][0], ROWS, COLS, heights);... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>& heights, vector<vector<bool>>& visited, queue<pair<int, int>>& q) {\n vector<vector<int>> dirs = {{1,0}, {-1,0}, {0,1}, {0,-1}};\n while(!q.empty()) {\n pair<int, int> coords = q.front();\n q.pop();\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>& heights, vector<vector<bool>>& visited, queue<pair<int, int>>& q) {\n vector<vector<int>> dirs = {{1,0}, {-1,0}, {0,1}, {0,-1}};\n while(!q.empty()) {\n pair<int, int> coords = q.front();\n q.pop();\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n const vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {-1,0}, {0, -1}};\n\n void processHeights(deque<pair<int, int>>& to_visit,\n std::set<std::pair<int, int>>& can_flow,\n vector<vector<int>>& heights, int n, int m,\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n const vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {-1,0}, {0, -1}};\n\n void processHeights(deque<pair<int, int>>& to_visit,\n std::set<std::pair<int, int>>& can_flow,\n vector<vector<int>>& heights, int n, int m,\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int h = heights.size();\n int w = heights[0].size();\n\n vector<vector<char>> atlantic(h, vector<char>(w, '_'));\n vector<vector<char>> pacific(h, vector<char>(w, '_'));;\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int h = heights.size();\n int w = heights[0].size();\n\n vector<vector<char>> atlantic(h, vector<char>(w, '_'));\n vector<vector<char>> pacific(h, vector<char>(w, '_'));;\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir={{0,1},{0,-1},{1,0},{-1,0}};\n void util(int i,int j,vector<vector<int>>& a,vector<vector<int>>& oc)\n {\n oc[i][j]=1;\n int n=a.size(),m=a[0].size();\n for(auto t: dir)\n {\n int x=i+t[0],y=j+t[1];\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "struct pair_hash\n{\n std::size_t operator()(std::pair<int,int> value) const\n {\n return value.first*31+value.second;\n }\n};\n\nusing unordered_pair_set = std::unordered_set<std::pair<int, int>, pair_hash>;\n\nclass Solution\n{\npublic:\n std::vector<std::vector<int>> pacificAtlantic(c... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n int m, n;\n vector<vector<int>> pacific;\n vector<vector<int>> atlantic;\n bool valid(int x, int y) {\n return x >= 0 && x < m && y >= 0 && y < n;\n }\n const vector<vector<int>> directions = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};\n void flow(int x, int ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n\n map<pair<int, int>, bool> visited;\n void dfs(int i, int j, vector<vector<int>> & a, vector<vector<int>> &mark){\n if(visited[{i, j}]) return;\n // cout << i << \" \" << j << endl;\n int n = a.size();\n int m = a[0].size();\n vector<i... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "// unordered_set<pair<int, int>> is invalid!\n// We can just store the visited information to vector<vector<bool>> pacific(m, vector<bool>(n));\n// and vector<vector<bool>> atlantic(m, vector<bool>(n));\n// Ref: https://leetcode.com/problems/pacific-atlantic-water-f... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n queue<pair<int, int>> q1, q2;\n int n = heights.size();\n int m = heights[0].size();\n\n vector<vector<int>> pacific(n, vector<int> (m, 0));\n vector<vector<int>> atlantic... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\n int M;\n int N;\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n M = heights.size();\n if(M == 0) return {};\n N = heights[0].size();\n vector<vector<int>> pac = vector<vector<int>>(M, vector<int>(N, 0));\n vecto... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\n int M;\n int N;\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n M = heights.size();\n if(M == 0) return {};\n N = heights[0].size();\n vector<vector<int>> pac = vector<vector<int>>(M, vector<int>(N, 0));\n vecto... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m = heights.size();\n int n = heights[0].size();\n std::vector<std::vector<int>> result;\n std::vector<std::vector<std::pair<bool,bool>>> valid;\n std::vector<std::vec... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m = heights.size();\n int n = heights[0].size();\n std::vector<std::vector<int>> result;\n std::vector<std::vector<std::pair<bool,bool>>> valid;\n std::vector<std::vec... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\nprivate:\n void fillFrom(int row, int col, int pos, \n vector<vector<int>>& heights, vector<vector<int>>& flow){\n if(flow[row][col] >= pos)\n return;\n\n stack<pair<int, int>> dfs;\n dfs.push(make_pair(row, col));\n\n // cout << \"looking at \... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n auto bfs(int r, int c, bool isAtlantic, vector<vector<int>>& heights, set<pair<int, int>>& visitedA, set<pair<int, int>>& visitedP){\n int m = heights.size();\n int n = heights[0].size();\n stack<pair<int, int>> st;\n st.push({r, c});\n\n if... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "// bfs\n// work backwards, see if water from one ocean can climb to a cell through a increasing path\n\nclass Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n if (heights.empty() || heights[0].empty()) return {};\n int m = heights.size(), n = heig... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\n\n // 0 -> no, 1->p, 2->a, 3->b\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n \n int m = heights.size(), n = heights[0].size();\n\n vector<vector<int>>vis(m, vector<int>(n, 0));\n\n for(int i = 0; i<m; i++)\n {\n... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m = heights.size();\n if(m<=0) return {{}};\n int n = heights[0].size();\n\n queue<vector<int>> atlantic;\n queue<vector<int>> pacific;\n for(int i =0;i<m;i++){... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n //1 visited PC 2\n vector<int> dx ={1,-1,0,0};\n vector<int> dy ={0,0,1,-1};\n\n bool isValid(int x, int y , int m, int n){\n if(x<0 or y< 0) return 0;\n if(x>=m or y>=n) return 0;\n return 1;\n }\n\n void bfs(queue<pair<int,int>> &q, vecto... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n // create matrices canFlowToAtlantic and canFlowToPacific using modified BFS from all shore squares\n\n vector<vector<int>> result;\n\n int n = heights.size();\n int m = heights[... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n\n void bfs(int i,int j,vector<vector<int>>&a,vector<vector<bool>>&vis){\n int n=a.size();\n int m=a[0].size();\n queue<pair<int,int>>q;\n q.push({i,j});\n int delr[4]={1,-1,0,0};\n int delc[4]={0,0,1,-1};\n \n while(!q.e... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "#include <vector>\n#include <queue>\n\n\nusing namespace std;\n\nclass Solution {\n\npublic:\n int x[5] = {0, 0, -1, 1};\n int y[5] = {1, -1, 0, 0};\n\n bool check_limits(vector<vector<int>>& heights, int r, int c) {\n if(r >= 0 && r < heights.size() && c >= 0 && c < heights[0].size()) { re... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n int m;\n int n;\n vector<vector<int>> heights;\n vector<vector<int>> directions = {{0,1},{0,-1},{1,0},{-1,0}};\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n if(heights.size()==0 || heights[0].size()==0) return {};\n\n m = he... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n\n void getPoss(queue<vector<int>> q, vector<vector<int>> &ocean, vector<vector<int>> &vis, vector<vector<int>> &a, int n, int m) {\n vector<vector<int>> pos = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n while(!q.empty()) {\n vector<int> co = q.front();\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m = heights.size();\n int n = heights[0].size();\n vector<vector<int>> res;\n vector<vector<bool>> pacific(m, vector<bool>(n));\n vector<vector<bool>> atlantic(m, vector<bool>(n));\n\n f... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n \n\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n if (heights.size() == 0 || heights[0].size() == 0) return {};\n\n landHeights = heights;\n m = heights.size();\n n = heights[0].size();\n\n queue<vector<int>> pQ;\... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n // space complexity : O(m*n)\n // time complexity : O(m*n)\n void bfs(vector<vector<int>>& heights,int row,int col,vector<vector<int>>&visited,int rows,int cols){\n visited[row][col] = 1;\n queue<pair<int,int>>q;\n q.push({row,col});\n int dr... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n if (heights.empty()) return {};\n\n int n = heights.size(), m = heights[0].size();\n vector<vector<bool>> pacific(n, vector<bool>(m, false));\n vector<vector<bool>> atlantic(n, v... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n vector<vector<int>> res;\n unordered_map<int,bool> visitedAtlantic;\n unordered_map<int,bool> visitedPacific;\n int m=heights.size(),n=heights[0].size();\n vector<vector<i... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(int i, int j, vector<vector<int>>& h, vector<vector<int>>& vis, int n, int m) {\n queue<pair<int, int>> q;\n q.push({i, j});\n vis[i][j] = 1;\n vector<pair<int, int>> moves = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\n \n while (!q... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n \n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n if (heights.size() == 0 || heights[0].size() == 0){\n return {};\n }\n m_rows = heights.size();\n m_cols = heights[0].size();\n queue<vector<int>> pacific... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n\n void bfs(int x_i, int y_i, vector<vector<int>> &grid, vector<vector<int>>& vis) {\n int r = grid.size();\n int c = grid[0].size();\n vector<int> dr = {-1, 1, 0, 0};\n vector<int> dc = {0, 0, -1, 1};\n vis[x_i][y_i] = 1;\n queue<pair... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(const vector<vector<int>>& h, int row, int col, unordered_set<int>& s, const int N) {\n s.insert(row * N + col);\n queue<pair<int, int>> q;\n q.push({row, col});\n \n while (!q.empty()) {\n auto [r, c] = q.front();\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n bool inValidCoord(int i, int j, int m, int n){\n return (i >=0 && i<m) && ( j >=0 && j < n);\n }\n\n void dfsFunc(int i, int j, int m, int n, set<pair<int,int>>& visit, vector<vector<int>>& heights){\n stack<pair<int,int>> dfsStack;\n dfsStack.pus... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(vector<vector<int>> &heights, map<vector<int>,int> &st,int row,int col,vector<vector<int>> &visit,int m,int n){\n //base case\n\n visit[row][col] = 1;\n st[{row,col}] = 1;\n for(int i=-1;i<2;i++){\n if(row+i>=0 && row+i < m &&... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(vector<vector<int>> &heights, map<vector<int>,int> &st,int row,int col,vector<vector<int>> &visit,int m,int n){\n //base case\n\n visit[row][col] = 1;\n st[{row,col}] = 1;\n for(int i=-1;i<2;i++){\n if(row+i>=0 && row+i < m &&... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n const int n = heights.size(), m = heights[0].size();\n vector<vector<int>> adj(n * m + 2);\n for (int i = 0; i < n; ++ i) {\n adj[n * m].push_back(i * m);\n adj[n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(int x, int y, vector<vector<int>>& grid, vector<vector<bool>>& visited) {\n visited[x][y] = true;\n queue<pair<int, int>> q;\n q.push({ x, y });\n while (!q.empty()) {\n int size = q.size();\n for (int i = 0; i < size... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n // Nodes flow to pacific ocean\n vector<vector<bool>> pacific = reachOcean(heights);\n\n // Flip the input heights to get nodes flow to atlantic ocean\n reverse(heights.begin(), ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\n void bfs(queue<pair<int, int>>& q, vector<vector<bool>>& reachable,\n vector<vector<int>>& heights, int m, int n) {\n vector<vector<int>> d = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n while (!q.empty()) {\n auto it = q.front();\n q.pop();\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "vector<int> dx = {1,-1,0,0};\nvector<int> dy = {0,0,1,-1};\n\nvoid bfs(vector<vector<int>> & heights, int x, int y, vector<vector<int>> &vis, set<pair<int,int>> &ans)\n{\n int m = heights.size();\n int n = heights[0].size();\n queue<pair<int,int>> q;\n vis[x][y]=1;\n q.push({x,y});\n\n wh... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int, int> > getNeighbours(pair<int, int> node, int rows, int cols) {\n vector<int> dx = {-1, 1, 0, 0};\n vector<int> dy = {0, 0, -1, 1};\n vector<pair<int, int> > neighbours;\n int dSz = dx.size();\n int row = node.first;\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n // Analysis\n // Method1: 反向来求,就是已知接触的点。 来反向求取的他们的令居。。然后推送\n // 否则,正向来求取。。因为存在相互通路的关系。。(a <-> b) 否则不好求取。\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int n_rows = heights.size();\n int n_cols = heights[0].size();\n vect... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\npublic:\n int dx[4] = {1, -1, 0, 0};\n int dy[4] = {0, 0, -1, 1};\n\n void dfs(vector<int> src, map<vector<int>, int>& ocean,\n vector<vector<int>>& heights, int n, int m) {\n if (ocean.count(src)) {\n return;\n }\n ocean[src] = 1;\n\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "void dfs_p(vector<vector<int>>& heights, unordered_map<int, bool>& p, int i, int j) {\n if (p[i * heights[0].size() + j] == true) return;\n\n p[i * heights[0].size() + j] = true;\n\n if (i + 1 < heights.size() && heights[i + 1][j] >= heights[i][j]) {\n dfs_p(heights, p, i + 1, j);\n }\n ... |
417 | <p>There is an <code>m x n</code> rectangular island that borders both the <strong>Pacific Ocean</strong> and <strong>Atlantic Ocean</strong>. The <strong>Pacific Ocean</strong> touches the island's left and top edges, and the <strong>Atlantic Ocean</strong> touches the island's right and bottom edges.</p>
<p>... | 3 | {
"code": "class Solution {\n int m, n;\n vector<vector<int>>ret;\n vector<vector<vector<int>>>visited;\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& grid) {\n m = grid.size(), n = m?grid[0].size():0;\n if(!m || !n)\n return {};\n visited = vector<vect... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.