id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
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": "/*\ngrid size is less\nwater moves to cell less height or equal\n*/\nclass Solution {\npublic:\n vector<vector<int>> dir={{0,1},{1,0},{0,-1},{-1,0}};\n void bfs(vector<vector<bool>>& s,vector<vector<int>>& h,bool ocean){\n int m=h.size();\n int n=h[0].size();\n queue<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>... | 3 | {
"code": "class Solution {\npublic:\n\n#define F first\n#define S second\n\n int dx[4]={0, -1, 0, 1};\n int dy[4]={1, 0, -1, 0};\n\n vector<vector<int>> board;\n\n bool check(int x, int y) {\n int m=board.size();\n int n=board[0].size();\n return (x >= 0 && y >= 0 && x < ... |
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#define F first\n#define S second\n\n int dx[4]={0, -1, 0, 1};\n int dy[4]={1, 0, -1, 0};\n\n vector<vector<int>> board;\n\n bool check(int x, int y) {\n int m=board.size();\n int n=board[0].size();\n return (x >= 0 && y >= 0 && x < ... |
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#define F first\n#define S second\n\n int dx[4]={0, -1, 0, 1};\n int dy[4]={1, 0, -1, 0};\n\n vector<vector<int>> board;\n\n bool check(int x, int y) {\n int m=board.size();\n int n=board[0].size();\n return (x >= 0 && y >= 0 && x < ... |
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:\nvoid pcfHelper(std::vector<std::vector<int>>& heights, std::set<std::vector<int>>& ans, bool pacific) {\n std::set<std::vector<int>> visited;\n std::queue<std::vector<int>> q;\n if (pacific) {\n for (int j = 0; j < heights[0].size(); j++) {\n q.push({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>... | 3 | {
"code": "class Solution {\npublic:\n\n map<pair<int,int>, int>pac;\n map<pair<int,int>, int>atl;\n\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n \n int rows = heights.size();\n int cols = heights[0].size();\n\n \n\n for(int i=0; i<cols; 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>... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(pair<int, int> node, vector<vector<int>>& vis,\n vector<vector<vector<pair<int,int>>>>& adj,\n vector<vector<int>>& pacific, vector<vector<int>>& atlantic, pair<int,int> parent, vector<vector<int>>& heights) {\n // if(parent.first!=-1 ... |
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 <stack>\n#include <iostream>\n\nusing namespace std;\n\nclass Node {\npublic:\n int i;\n int j;\n\n bool pacific;\n bool atlantic;\n\n vector<Node*> heights;\n\n Node() :\n pacific(false),\n atlantic(false)\n {}\n};\n\nclass Solution {\npub... |
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 flood(int r, int c, int n, int m, vector<vector<int>>& h,\n vector<vector<int>>& visited) {\n queue<pair<int, int>> q;\n q.push({r, c});\n vector<vector<int>> dir = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};\n\n // visited[r][c] = 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": "class Solution {\npublic:\n set< pair<int,int> > bfs(queue<pair<int,int> > q, const vector<vector<int> >& heights)\n {\n vector<vector<int> > updates ={{1,0},{-1,0},{0,1},{0,-1}};\n vector<vector<int> > visited(heights.size(), vector<int>(heights[0].size(), 0));\n set< pair<int,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 play(int x, int y, int n, int m, vector<vector<bool>>& flag, vector<vector<int>>& heights){\n flag[x][y] =true;\n vector<vector<int>> r{{-1,0}, {1,0}, {0,1}, {0,-1}};\n for (int k = 0; k < 4; k++){\n int x1 = x+ r[k][0];\n int y... |
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>> ans;\n set<vector<int>> s;\n void helper(int i,int j,vector<vector<int>>& heights,int prev){\n if(i<0||j<0||i>=heights.size()||j>=heights[0].size()||heights[i][j]<prev||s.count({i,j})) return;\n s.insert({i,j});\n helper(i+1,j,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 vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int rows = heights.size();\n int cols = heights[0].size();\n vector<vector<bool>>fromPacific(rows, vector<bool>(cols, false));\n vector<vector<bool>>fromAtlantic(rows, vector<boo... |
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 // queue<vector<int>> q;\n\n\n // int n = heights.size();\n // int m = heights[0].size();\n // vector<vector<pair<int,int>>> possibe(n,vector... |
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(unordered_map<int,unordered_map<int,int>>& ocean,queue<pair<int,int>>&q, int n, int m, unordered_map<int,unordered_map<int,bool>>&vis,vector<vector<int>>& heights)\n {\n while(!q.empty())\n {\n pair<int,int> x = 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>... | 3 | {
"code": "class Solution {\npublic:\n set<vector<int>>p_area;\n set<vector<int>>a_area;\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m=heights[0].size();\n int n=heights.size();\n for(int row=0;row<n;++row ){\n dfs(heights,p_area,row,0,heights[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>... | 3 | {
"code": "class Solution {\npublic:\n set<vector<int>>p_area;\n set<vector<int>>a_area;\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int m=heights[0].size();\n int n=heights.size();\n for(int row=0;row<n;++row ){\n dfs(heights,p_area,row,0,heights[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>... | 3 | {
"code": "typedef vector<int> Point;\n\nclass Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n int rows = heights.size();\n int cols = heights[0].size();\n\n vector<Point> pacific_start;\n vector<Point> atlantic_start;\n \n for (... |
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 vector<vector<int>> result;\n vector<vector<bool>> visited_pacific;\n vector<vector<bool>> visited_atlantic;\n\n int rows;\n int cols;\n\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n rows = heights.size();\n cols = height... |
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>> directions = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n vector<vector<int>> heights;\n\n bool isValid(const vector<int>& node) {\n if (node[0] < 0 || node[0] >= heights.size()) {\n return false;\n }\n\n if (node[1] < 0 || 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\n void bfs(const vector<vector<int>>& heights, const vector<vector<int>> &sources, set<vector<int>>& canReachOcean) {\n queue<vector<int>> q;\n set<vector<int>> discovered;\n for (auto& source : sources) {\n int r = source[0];\n 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:\nstruct pair_hash {\n template <class T1, class T2>\n size_t operator() (const pair<T1, T2> &pair) const {\n auto hash1 = hash<T1>{}(pair.first);\n auto hash2 = hash<T2>{}(pair.second);\n return hash1 ^ hash2;\n }\n};\n\nvoid bfs(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>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<vector<int>>> a;\n vector<vector<int>> matrix;\n int dx[4] = {1,-1,0,0};\n int dy[4] = {0,0,1,-1};\n bool valid (int r, int c) {\n return (r >= 0 and c >= 0 and r < matrix.size() and c < matrix[0].size());\n }\n void bfs(int i, int j, in... |
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 dfs(int r,int c,set<vector<int>> &vis,int prevht\n ,vector<vector<int>>& heights)\n {\n if(r<0 || r>=heights.size() || c<0 || c>=heights[0].size()\n || heights[r][c]<prevht || vis.find({r,c})!=vis.end())\n return;\n\n vis.insert({r,c});\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 set<vector<int>> pacific, atlantic;\n vector<vector<int>> results;\n int rows = heights.size() - 1, columns = heights[0].size() - 1;\n for (int i = 0; i <= columns; 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>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(int row, int col, vector<vector<int>>& heights, vector<vector<bool>>& visited) {\n\n\n int ROWS = heights.size();\n int COLS = heights[0].size();\n\n vector<vector<int>> neighbors({ {0,1}, {0,-1}, {1,0}, {-1,0} } );\n\n queue<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>... | 3 | {
"code": "class Solution {\npublic:\n\n void bfs(const vector<vector<int>>& heights, const vector<vector<int>> &sources, set<vector<int>>& canReachOcean) {\n stack<vector<int>> q;\n set<vector<int>> discovered;\n for (auto& source : sources) {\n int r = source[0];\n 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 {\nprivate:\n set<pair<int, int>> bfs(list<pair<int, int>> queue, vector<vector<int>>& heights, vector<vector<bool>> visited) {\n set<pair<int, int>> flow;\n vector<vector<int>> directions = {{1,0}, {-1,0}, {0,1}, {0,-1}};\n while (queue.size()) {\n auto pos = queue.... |
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 isSafe(int i , int j , int m , int n )\n {\n return (i >= 0 && i < m && j >=0 && j <n);\n }\n void dfs(int i , int j , int m , int n , vector<vector<bool>>& vis , vector<vector<int>>& heights)\n {\n vis[i][j] = true;\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>... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n vector<vector<int>> res;\n int m = heights.size();\n int n = heights[0].size();\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>... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>&heights,vector<vector<int>>&visited,int r,int c){ \n vector<vector<int>>help;\n help.push_back({0,1});\n help.push_back({0,-1});\n help.push_back({1,0});\n help.push_back({-1,0});\n visited[r][c]=1;\n for(int i=0;i<4;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 int dp[205][205]; //to check visited or not\n void dfs(int i, int j,int prevVal, vector<vector<int>>& heights, vector<vector<int>>& path){\n vector<int>v;\n if(i<0 || j<0 || i>=heights.size() || j>=heights[0].size()) return;\n if(heights[i][j] < prevVal... |
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(vector<vector<int>>& heights, vector<vector<bool>>& visited, int i, int j, int& m, int& n) {\n visited[i][j] = true;\n vector<vector<int>> dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};\n for(int x=0;x<4;x++) {\n int di = i+dir[x][0];\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": "//Manvi\nclass Solution {\npublic:\n\n void dfs(vector<vector<int>>& heights, vector<vector<bool>>& visit, int r, int c, int prev_h)\n {\n int n = heights.size();\n int m = heights[0].size();\n vector<vector<int>>dir = {{0,1}, {0,-1}, {1,0}, {-1,0}};\n visit[r][c] = true;\... |
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;\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 vector<vector<... |
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;\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 vector<vector<... |
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.size() == 0 || heights[0].size() == 0) return {};\n\n numRows = heights.size();\n numCols = heights[0].size();\n landHeights = heights;\n\n queue<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>... | 3 | {
"code": "class Solution {\npublic:\n void getFlowMap(vector<vector<int>>& heights, set<pair<int, int>>& seen_tiles,\n vector<vector<int>>& can_reach) {\n\n deque<pair<int, int>> flow_tiles(seen_tiles.begin(), seen_tiles.end());\n\n for (; !flow_tiles.empty(); flow_tiles.pop_front... |
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 \n if (heights.size()==0 || heights[0].size()==0){\n return vector<vector<int>>();\n } \n numRows = heights.size();\n numCols = heights[0].size();\n land... |
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\n bool flow(int cur_height, int next_height){\n return next_height >= cur_height;\n }\n\n void bfsCoastPac(queue<vector<int>>& q, vector<vector<int>>& heights, vector<vector<bool>>& t_pac){\n vector<vector<bool>> visit(this->m, 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 void dfs(vector<vector<int>>& heights,vector<vector<bool>>& to_reach,int row, int col){\n if(to_reach[row][col]) return;\n to_reach[row][col]=true;\n\n int rows=heights.size();\n int cols =heights[0].size();\n vector<vector<int>> directions{... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n for(int i = 0; i < prerequisites.size(); i++){\n int temp = prerequisites[i][0];\n int conn = prerequisites[i][1];\n bool first = true;\n bool second = fa... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n\n vector<int> inDegree(numCourses,0);\n\n for(int i=0;i<prerequisites.size();i++){\n inDegree[prerequisites[i][0]]++;\n }\n\n queue<int> q;\n\n for(int i=0;i<n... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prereq) {\n vector<int>dependency(numCourses);\n queue<int>courses_queue;\n int count=0;\n for(int i=0;i<prereq.size();i++){\n dependency[prereq[i][0]]++;\n }\n\n for(int ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n for(int i {0};i<prerequisites.size();++i)\n {\nint q{0};\n \n \n \n int t{prerequisites[i][0]};\n \n auto f {find_if(prerequisites.begin... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& p) {\n int n=numCourses;\n vector<int> indegree(n,0);\n int m=p.size();\n for(int i=0;i<m;i++)\n {\n indegree[p[i][0]]++;\n }\n queue<int> q;\n for(int i=0;i... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& p) {\n int n=numCourses;\n vector<int> indegree(n,0);\n int m=p.size();\n for(int i=0;i<m;i++)\n {\n indegree[p[i][0]]++;\n }\n queue<int> q;\n for(int i=0;i... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n queue<int> q;\n vector<int> inOrder(numCourses,0);\n\n for(int i=0;i<prerequisites.size();++i){\n inOrder[prerequisites[i][1]]++;\n }\n\n for(int i=0;i<numCour... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\nvoid solve(int n, vector<vector<int>>&g, unordered_map<int, int>&m,vector<int>&ans){\nqueue<int>q;\nint a=g.size();\nfor(int i=0;i<n;i++){\n if(m[i]==0)\n q.push(i);\n}\nwhile(!q.empty()){\n int front=q.front();\n q.pop();\n ans.push_back(front);\n for(int i=0;i... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& preq) {\n vector<int>adj[numCourses];\n vector<int>indegree(numCourses,0);\n for(int i=0;i<preq.size();i++){\n adj[preq[i][0]].push_back(preq[i][1]);\n indegree[preq[i][1]]++;\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "const int N = 2005;\nvector<int>ad_list[N];\nint col[N];\nbool cycle;\nvoid detectCycle(int u)\n{\n col[u] = 1;\n for(auto &j:ad_list[u])\n {\n if(!col[j])\n detectCycle(j);\n else if(col[j] == 1)\n cycle = true;\n }\n col[u] = 2;\n}\nclass Solution {\npub... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n void dfs(vector<vector<int>> &graph,int src,vector<int> &indegree )\n {\n for(auto it:graph[src])\n {\n if(--indegree[it]==0)\n dfs(graph,it,indegree);\n } \n }\n bool canFinish(int n, vector<vector<int>>& p) {\n... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> adj(numCourses);\n vector<int> intake(numCourses, 0);\n\n for (int itr = 0; itr < prerequisites.size(); itr++) {\n int a = prerequisites[itr][0];\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n\n vector<int> adj[2001];\n int vis[2001];\n int indegree[2001];\n\n vector<int> topo;\n\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n int vx = numCourses;\n\n for(int i=0; i<prerequisites.size(); i++) {\n adj... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 0 | {
"code": "class Solution {\npublic:\n\n bool bfs(int numCourses,vector<int> adj[],vector<vector<int>>& prerequisites)\n {\n vector<int> indegree(numCourses,0);\n\n\n queue<int> q;\n\n for(int i=0;i<prerequisites.size();i++)\n indegree[prerequisites[i][1]]++;\n\n for(int ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool dfs(int s,vector<int>adj[],vector<int>&vis,bool &cycle){\n vis[s] = 1;\n \n for(int child:adj[s]){\n if(vis[child]==0){\n dfs(child,adj,vis,cycle);\n if(cycle) return cycle;\n }\n else if(... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n int n = numCourses;\n int size = prerequisites.size();\n vector<int> adj[n];\n vector<int> indeg(n, 0);\n for(int i=0;i<size;i++){\n adj[prerequisites[i][1]].p... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool dfs(int i, vector<int> g[], vector<int> &visit){\n visit[i] = 1;\n for(int x : g[i]){\n if(visit[x] == 1 || (visit[x] == 0 && !dfs(x, g, visit)))\n return false;\n }\n visit[i] = 2;\n return true;\n }\n b... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<int>graph[numCourses];\n vector<int>indegree(numCourses,0);\n for(auto &p: prerequisites){\n int u = p[0];\n int v = p[1];\n graph[u].push_back(... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<int>adj[numCourses];\n for(int i=0;i<prerequisites.size();i++){\n adj[prerequisites[i][1]].push_back(prerequisites[i][0]);\n }\n vector<int>indegree(numCourses... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool isCyclic(int n, vector<int> adj[]) {\n \n vector<int> indegree(n, 0);\n for(int i=0;i<n;i++){\n for(auto it: adj[i]){\n indegree[it]++;\n }\n }\n \n // Kahn's Algo\n queue<int> q;\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int V, vector<vector<int>>& pre) {\n vector<int>indeg(V,0);\n vector<int>adj[V];\n\n \n for(int i=0;i<pre.size();i++){\n int first=pre[i][0];\n int second=pre[i][1];\n adj[first].push_back(second);\n indeg... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> courses(numCourses);\n vector<int> indegree(numCourses,0);\n int res = 0;\n\n for(auto& it : prerequisites){\n courses[it[1]].push_back(it[0]);\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool isCyclic(int i, vector<int> adj[], vector<int> &vis, vector<int> &temp_vis)\n {\n vis[i] = 1;\n temp_vis[i] = 1;\n\n for (int j:adj[i])\n {\n if (temp_vis[j]) return true;\n else if (!vis[j])\n if (isCyc... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n \n int n = numCourses;\n vector<vector<int>> adj(n);\n vector<int> indegree(n,0);\n queue<int> q;\n\n for(auto& curr : prerequisites)\n {\n adj[c... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 1 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites)\n {\n vector<int> indegree(numCourses);\n vector<vector<int>> adj(numCourses);\n for(auto& edge: prerequisites)\n {\n adj[edge[1]].push_back(edge[0]);\n ind... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\n void dfs(\n int node,\n vector<vector<int>>& adjList,\n vector<int>& state,\n bool& possible\n )\n {\n if (state[node] == 2){\n return;\n }\n \n if(state[node] == 1){\n possible = false;\n r... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> adj(numCourses);\n vector<int> indegree(numCourses, 0);\n for(auto& pre : prerequisites) {\n adj[pre[1]].push_back(pre[0]);\n indegree[pre[0]]... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n // Helper function for DFS to detect cycles\n bool dfs(vector<vector<int>>& adj, int node, vector<int>& vis, vector<int>& recStack) {\n // Mark the current node as visited and add it to the recursion stack\n vis[node] = 1;\n recStack[node] = 1;\n\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int V, vector<vector<int>>& pre_req) {\n vector<int>adj[V];\n //making adjacency list;\n for(auto i: pre_req){\n adj[i[1]].push_back(i[0]);\n }\n //we will solve this question using topological sort;\n //writing ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prereq) {\n vector<vector<int>> v(numCourses);\n unordered_map<int,int> m;\n for (int i=0; i<prereq.size(); ++i) {\n v[prereq[i][0]].push_back(prereq[i][1]);\n m[prereq[i][1]]++;\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n \n\n // make a hash_map marking the number of pre-reqs for the course\n // also make a hash_map marking the outbound edges for each course\n // create a queue with just the ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int V, vector<vector<int>>& prerequisites) {\n \n vector<int>adj[V] ;\nfor(auto it : prerequisites){\n adj[it[0]].push_back(it[1]);\n}\n\t \n\t queue<int> q ;\n\t vector<int> topo ; \n\t vector<int> indeg(V,0);\n\t \n\t for(i... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n \n\n // make a hash_map marking the number of pre-reqs for the course\n // also make a hash_map marking the outbound edges for each course\n // create a queue with just the ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<int> adj[numCourses]; \n int n = prerequisites.size() ;\n for(auto it : prerequisites){\n adj[it[1]].push_back(it[0]);\n }\n\n queue<int> q ;\n v... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n \n\n // make a hash_map marking the number of pre-reqs for the course\n // also make a hash_map marking the outbound edges for each course\n // create a queue with just the ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 2 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n \n\n // make a hash_map marking the number of pre-reqs for the course\n // also make a hash_map marking the outbound edges for each course\n // create a queue with just the ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n \n\n // make a hash_map marking the number of pre-reqs for the course\n // also make a hash_map marking the outbound edges for each course\n // create a queue with just the ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<int> indegrees(numCourses);\n vector<vector<int>> adj(numCourses);\n for(auto pre : prerequisites){\n indegrees[pre[0]]++;\n adj[pre[1]].push_back(pre[0]);... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& pre) {\n vector<int> vis(numCourses, 0);\n vector<vector<int>> adj(numCourses);\n for(auto u : pre) {\n adj[u[0]].push_back(u[1]);\n }\n\n for(int i=0;i<numCourses;i++) {\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool isCyclic(int i, int numCourses, vector<int> adj[], vector<bool> &vis, vector<bool> &tempvis){\n vis[i]=true;\n tempvis[i]=true;\n for(int u:adj[i]){\n if(tempvis[u])\n return true;\n else if (!vis[u])\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\nprivate:\n bool isCyclic(int node, vector<int>& vis, vector<int>& pathVis, vector<vector<int>>& adj){\n vis[node]=1;\n pathVis[node]=1;\n for(auto n: adj[node]){\n if(!vis[n]){\n if(isCyclic(n, vis, pathVis, adj) == true){\n return tru... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\nprivate:\n bool isCyclic(int node, vector<int>& vis, vector<int>& pathVis, vector<vector<int>>& adj){\n vis[node]=1;\n pathVis[node]=1;\n for(auto n: adj[node]){\n if(!vis[n]){\n if(isCyclic(n, vis, pathVis, adj) == true){\n return tru... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool dfs(int src, unordered_map<int, bool> &mp, vector<vector<int>> &adj) {\n if(mp.find(src) != mp.end()) return mp[src];\n mp[src] = false;\n for(int i: adj[src]) {\n if(!dfs(i, mp, adj)) return mp[src] = false;\n }\n return mp[... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int n, vector<vector<int>>& prerequisites) {\n vector<int> adj[n];\n vector<int> indegree(n, 0);\n vector<int> ans;\n\n for(auto x: prerequisites){\n adj[x[0]].push_back(x[1]);\n indegree[x[1]]++;\n }\n\n... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n int preCount[2000]={0};\n vector<int> depends[numCourses];\n for(auto x: prerequisites){\n depends[x[1]].push_back(x[0]);\n preCount[x[0]]++;\n }\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int n, vector<vector<int>>& arr) {\n vector<int>indegree(n,0);\n vector<int>adj[n];\n for(auto it:arr)\n {\n adj[it[1]].push_back(it[0]);\n indegree[it[0]]++; \n }\n queue<int>q;\n for(int i... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\nprivate:\n vector<vector<int>> createGraph(int v, vector<vector<int>>& edges, vector<int>& ind){\n vector<vector<int>> adjL(v);\n\n for(auto it: edges){\n adjL[it[1]].push_back(it[0]);\n ind[it[0]]++;\n }\n\n return adjL;\n }\n\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> adj(numCourses); \n for(auto it : prerequisites) {\n adj[it[1]].push_back(it[0]);\n }\n\n vector<int> indegree(numCourses, 0); \n for(int... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> adj(numCourses);\n vector<int> vis(numCourses, 0);\n vector<int> dfsVis(numCourses, 0);\n for(auto it : prerequisites) {\n adj[it[1]].push_back(it... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int n, vector<vector<int>>& prereq) {\n vector<vector<int>> adj(n, vector<int> ());\n vector<vector<int>> derived(n, vector<int> ());\n for(int i = 0; i < prereq.size(); i++){\n adj[prereq[i][1]].push_back(prereq[i][0]);\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n unordered_map<int,vector<int>> g;\n for (vector<int> &p : prerequisites) {\n g[p[1]].push_back(p[0]);\n }\n vector<int> colors(numCourses, 0);\n for (int i = 0... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> adj(numCourses);\n for (const auto& pre : prerequisites) {\n adj[pre[1]].push_back(pre[0]);\n }\n \n vector<bool> visited(numCourses, false... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\n unordered_map<int, vector<int>> preMap;\n set<int> visit;\n bool dfs(int cour) {\n if(visit.find(cour) != visit.end()) return false;\n if (preMap[cour].empty()) return true;\n\n visit.insert(cour);\n for (auto & pre : preMap[cour]) {\n if(!... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n unordered_map<int, vector<int>> cpMap;\n \n for (auto const& edge : prerequisites) {\n cpMap[edge[0]].push_back(edge[1]);\n }\n\n vector<bool> visited(numCours... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n\n bool dfs(int node, vector<vector<int>> &adj, vector<bool> &vis, vector<bool> &s){\n vis[node] = true;\n s[node] = true;\n\n for(auto neigh:adj[node]){\n if(!vis[neigh]){\n if(dfs(neigh, adj, vis, s)){\n retur... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {\n vector<vector<int>> prereqs(numCourses);\n for(int i = 0; i < prerequisites.size(); ++i){\n prereqs[prerequisites[i][0]].push_back(prerequisites[i][1]);\n }\n vector<... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n\n int dfs(map<int, vector<int>> &graph, int curr, vector<int> &vis){\n if(vis[curr]==1)\n {\n return true;\n }\n if(vis[curr]==2)\n {\n return false;\n }\n vis[curr] = 1;\n int ans = false;\n ... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "class Solution {\npublic:\n\n bool cycle(unordered_map<int, vector<int>>& adj, vector<bool>& visit, vector<bool>& dfsvisit, int node){\n visit[node] = true;\n dfsvisit[node] = true;\n for(int neb : adj[node]){\n if(!visit[neb]){\n if(cycle(adj, visit, dfsvi... |
207 | <p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i<... | 3 | {
"code": "bool topo(vector<vector<int>>graph){\n int n=graph.size();\n vector<int>r(n,0);\n vector<int>ans;\n for(auto it:graph){\n for(auto x:it){\n r[x]++;\n }\n }\n queue<int>q;\n for(int i=0;i<n;i++){\n if(r[i]==0){\n q.push(i);\n }\n }\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.