id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n //๊ฐ ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ‚ค๋กœ ํ•˜๊ณ  ํŒจ๋ฐฐ ํšŸ์ˆ˜๋ฅผ ๊ฐ’์œผ๋กœ ํ•˜๋Š” hash map ์ƒ์„ฑ - ๋ฐ˜๋Œ€๋กœ ํŒจ๋ฐฐ ํšŸ์ˆ˜๊ฐ€ ํ‚ค์ด๊ณ  ํ”Œ๋ ˆ์ด์–ด ๋ฐฐ์—ด์ด ๊ฐ’์ด๋ผ๋ฉด? ๋‘˜๋‹ค O(n*m)์ธ๋“ฏ\n //ํ•ด์‹œ๋งต ํ‚ค์— ๋Œ€ํ•ด์„œ loop ๋Œ๋ ค ๊ฐ’์ด 0๊ณผ 1์ธ ๊ฒฝ์šฐ์—๋งŒ answer์— ์ถ”๊ฐ€\n \n unordered_map<int, int> counts;\n ve...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n int n = matches.size();\n\n map<int,int>win, loss;\n\n for(auto it:matches) {\n win[it[0]]++;\n loss[it[1]]++;\n }\n vector<int>zero,one;\n for(au...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n \n //count losses\n unordered_multiset<int> losses;\n //unordered_set<int> winners;\n unordered_set<int> players;\n vector<vector<int>> loss(2);\n\n for (auto co...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n set<int> zero;\n set<int> one;\n set<int> fuckingloser;\n\n for (auto res: matches){\n int winner = res[0];\n int loser = res[1];\n\n // deal with wi...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n set<int> players;\n map<int,int> losers;\n for (int i = 0; i < matches.size(); i++) {\n losers[matches[i][1]]++;\n players.insert(matches[i][0]);\n players....
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> loseCount;\n int n = matches.size();\n for (int i = 0; i < n; ++i) {\n if (loseCount.find(matches[i][0]) == loseCount.end()) {\n loseCount[...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int,int>m;\n vector<vector<int>>vt;\n vector<int>v;\n set<int>s1;\n set<int>s2;\n for(int i=0;i<matches.size();i++)\n {\n m[matches[i][1]]++;\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int,int>m;\n for(auto it:matches){\n m[it[1]]++;\n }\n vector<int>list1;\n for(auto it:matches){\n if(m.find(it[0])==m.end()){\n list1...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> loseCounts;\n unordered_set<int> playerNum;\n vector<vector<int>> ans(2);\n int index = 0;\n int count = 0;\n \n while(index < matches.si...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> m;\n unordered_map<int, int> l;\n\n for(int i = 0; i < matches.size(); i++){\n m[matches[i][0]]++;\n m[matches[i][1]]++;\n l[matches...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int,int>lost_map;\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n for(auto it:matches)\n {\n int winner=it[0];\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n \n unordered_map <int, int> win;\n unordered_map <int, int> loss;\n vector<vector<int>> ans;\n \n vector<int> win_ans;\n vector<int> loss_ans;\n\n \n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n std::vector<int> no_looser;\n std::vector<int> one_looser;\n std::map<int,int> play_map;\n std::map<int,int> win_map;\n for(size_t i=0;i<matches.size();i++){\n \n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int,int> loss_count;\n set<int> players;\n \n // Count losses and track all players\n for (int i = 0; i < matches.size(); i++) {\n loss_count[matches[i][1]]++; // Increment loss count...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int,int> mWin;\n unordered_map<int,int> mPlay;\n unordered_map<int,int> mLoose;\n for(auto &vec : matches){\n mPlay[vec[0]]++;\n mPlay[vec[1]]++;\...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int,int> mPlay;\n unordered_map<int,int> mWin;\n unordered_map<int,int> mLoose;\n for(auto &vec : matches){\n mPlay[vec[0]]++;\n mPlay[vec[1]]++;\...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n vector<vector<int>> answer(2);\n unordered_map<int,int>freq_loser;\n set<int>teams;\n set<int>::iterator itr;\n \n for(auto num: matches) {\n teams.insert(nu...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> loserCount;\n unordered_set<int> players;\n vector<int> nonLosers;\n vector<int> oneTimeLosers;\n\n for(vector<int> arr: matches){\n players...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int, int>lose2;\n for(int i=0;i<matches.size();i++){\n lose2[matches[i][1]]++;\n }\n vector<int> answer2;\n for(auto pr: lose2){\n if(pr.second==1){\...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int,int> mp_def; //deaf_times\n unordered_map<int,int> play_cnt; //Player_Matches\n for(auto it:matches)\n {\n mp_def[it[1]]++;\n\n play_cnt[it[0]...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> losses;\n set<int> players;\n for (auto match: matches) {\n losses[match[1]]++;\n players.insert(match[0]);\n players.insert(match[1...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> losses;\n set<int> players;\n\n \n for ( auto match : matches) {\n players.insert(match[0]);\n players.insert(match[1]);\n loss...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> losses;\n set<int> players;\n for (auto match: matches) {\n losses[match[1]]++;\n players.insert(match[0]);\n players.insert(match[1...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n vector<vector<int>> ans;\n map<int, int> mp;\n set<int> st;\n for (auto it : matches) {\n mp[it[1]]++;\n st.insert(it[0]);\n st.insert(it[1]);\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int,int> mp;\n set<int> st;\n for(auto it:matches){\n int winner=it[0],loser=it[1];\n st.insert(winner);\n st.insert(loser);\n if(mp.find(los...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int,int> hashMap;\n set<int> ZeroLosts, OneLosts;\n \n for(vector<int> match: matches) {\n hashMap[match[1]]++;\n hashMap[match[0]]+=0;\n\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n set<int> played;\n map<int,int> losses;\n for(auto v:matches){\n played.insert(v[0]);\n played.insert(v[1]);\n losses[v[1]]++;\n }\n vector<ve...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution \n{\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n int n = matches.size();\n vector<vector<int>> ans;\n set<int> winr;\n set<int> losr;\n unordered_map<int,int> wins;\n unordered_map<int,int> loss;\n\n for(int ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n int n = matches.size();\n vector<vector<int>> ans;\n set<int> winr;\n set<int> losr;\n unordered_map<int,int> wins;\n unordered_map<int,int> loss;\n // int mx = ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n vector<int> playerLosses(10*10*10*10*10 + 1, -1);\n \n for (auto match: matches) {\n auto winner = match[0];\n auto loser = match[1];\n \n if (pl...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n unordered_map<int, int> lost;\n unordered_set<int> seen;\n vector<vector<int>> ans(2, vector<int>());\n for (auto match : matches)\n {\n seen.insert(match[0]);\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n vector<vector<int>> ans;\n set<int> winner; //unique winner\n set<int> loser; //unique loser\n unordered_map<int,int> m;\n for(auto a: matches){\n winner.insert(a...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n \n unordered_set<int> players;\n unordered_map<int, int> playersWhoLostMap;\n \n set<int> playersWhoNeverLost;\n set<int> playersWhoLostOnce;\n \n for (ve...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& m) {\n vector<vector<int>>ans(2);\n set<int>s;\n set<int>st;\n for(int i=0;i<m.size();i++){\n s.insert(m[i][0]);\n s.insert(m[i][1]);\n }\n for(int i=0;i<m.siz...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n set<int> w, w1, l;\n\n for(auto i : matches) {\n int lst = 0;\n if(w.find(i[0]) == w.end() && l.find(i[0]) == l.end()) {\n w.insert(i[0]);\n }\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n int N = matches.size(), max = 0;\n for (vector<int> match : matches){\n if (max < match[0]) max = match[0];\n if (max < match[1]) max = match[1];\n }\n vector<i...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int, int> losses;\n set<int> players; // To keep track of all players\n \n for (auto match: matches) {\n losses[match[1]] += 1;\n players.insert(match[0]);...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int,int>mpp;\n set<int>s,temp;\n for(int i=0;i<matches.size();i++){\n mpp[matches[i][1]]++;\n s.insert(matches[i][1]);\n temp.insert(matches[i][0]);\n ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int , int> in_deg , out_deg ; \n set<int> players ; \n for(auto& it:matches){\n players.insert(it[0]) ; \n players.insert(it[1]) ; \n\n in_deg[it[0]]++ ...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n set<int>winorloss;\n map<int,int>loss;\n for (auto i: matches){\n loss[i[1]]+=1;\n winorloss.insert(i[0]);\n winorloss.insert(i[1]);\n }\n vector<int>ans1...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n vector<int> no_loss;\n vector<int> one_loss;\n unordered_map<int,int> mp;\n for(auto x:matches){\n mp[x[1]]++;\n }\n unordered_set<int> st;\n for(auto...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n vector<vector<int>> ans;\n\n set<int> not_lost;\n set<int> lost_once;\n set<int> occured;\n\n for (auto match : matches) {\n\n // Add winner\n if (occure...
1,354
<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p> <p>Return <em>a list </em><code>answer</code><em> of size </em><code>2<...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findWinners(vector<vector<int>>& matches) {\n map<int, vector<int>> player;\n vector<int> not_lost, won_one;\n vector<vector<int>> ret;\n\n for(int i=0; i<matches.size(); i++) {\n \n //cout<<\"player is : \...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\n /*\n 0: top\n (x, y): 1 + row*x+y\n bottom: row*col+1 => total+1\n */\n int parent[20003];\n int size[20003];\n int row;\n int col;\n vector<int> dist = {1, 0, -1, 0, 1};\npublic:\n int latestDayToCross(int row, int col, vector<vector<int>>& c...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\n /*\n 0: top\n (x, y): 1 + row*x+y\n bottom: row*col+1 => total+1\n */\n int parent[20003];\n int size[20003];\n int row;\n int col;\n vector<int> dist = {1, 0, -1, 0, 1};\npublic:\n int latestDayToCross(int row, int col, vector<vector<int>>& c...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n // Parent array for Disjoint Set data structure (Union-Find)\n vector<int> parent;\n // Array to represent the four directional moves (left, right, down, up)\n int dirs[4][2] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};\n // M...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class UF {\npublic:\n vector<int> p;\n UF(int n) {\n p.resize(n);\n for (int i = 0; i < n; i++) {\n p[i] = i;\n }\n }\n int find(int x) {\n if (x != p[x]) {\n p[x] = find(p[x]);\n }\n return p[x];\n }\n void merge(int x, int ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\npublic:\n int d[5] = {-1,0,1,0,-1};\n int find(int n, vector<int> &parr){\n while(n != parr[n]){\n parr[n] = parr[parr[n]];\n n = parr[n];\n }\n return parr[n];\n }\n void join(int n1, int n2, vector<int> &parr, vector<int> &sz){\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\npublic:\n unordered_map<int,pair<int,int>> mp;\n int roots[100001];\n int find(int a){\n if(roots[a]==a)return a;\n int p=find(roots[a]);\n roots[a]=p;\n return p;\n }\n int unionNodes(int a,int b){\n int ap=find(a);\n int bp=find(b...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DSU\n{\n\npublic:\n vector<int>parent, size;\n int groupCount;\n\n DSU(int n): groupCount(n)\n {\n for (int i = 0; i <= n; i++)\n {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int findParent(int node)\n {\n if (parent[...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DSU\n{\npublic:\n vector<int> len;\n vector<int> parents;\n // vector<int> left, right, top, bottom;\n unordered_map<int,int>left, right;\n DSU(int n)\n {\n for(int i=0;i<=n;i++)\n {\n parents.push_back(i);\n len.push_back(1);\n // left...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DSU{\n public: \n int n,m;\n vector<vector<pair<int,int>>> parent;\n vector<vector<int>> size;\n\n DSU(int n ,int m){\n this -> n= n;\n this -> m = m;\n\n for(int i=0;i<n;i++){\n vector<pair<int,int>> v(m, {-1,-1});\n parent.push_back(v);\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DisjointSet {\n public:\n vector<int>parent,size;\n DisjointSet(int n){\n parent.resize(n);\n size.resize(n);\n for(int i=0;i<n;i++){\n parent[i]=i;\n size[i]=1;\n }\n }\n int findUParent(int node){\n if(node==parent[node]){\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DSU{\n vector<int> parent, size;\npublic:\n DSU(int n){\n parent.resize(n+1), size.resize(n+1);\n for(int i=0; i<=n; i++){\n parent[i]=i;\n size[i]=1;\n }\n }\n int findUPar(int node){\n if(parent[node]==node) return node;\n return ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\npublic:\n class DisjointSet {\n public:\n vector<int> parent, size;\n DisjointSet(int n) {\n parent.resize(n + 1);\n size.resize(n + 1);\n for (int i = 0; i <= n; i++) {\n parent[i] = i;\n size[i] = 1;\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\npublic:\nvector<vector<int>> possiblePaths = {{1,0},{0,1},{-1,0},{0,-1}};\n int latestDayToCross(int row, int col, vector<vector<int>>& cells) {\n int start=0;\n int end=cells.size() - 1;\n int ans=-1;\n vector<vector<int>> grid(row+1, vector<int>(col+1, 0))...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class UnionFindLandMatrix {\nprivate:\n const int NULL_NODE = -1;\n unordered_map<int, int> node2Parent;\n unordered_map<int, int> sizeOfSet;\npublic:\n UnionFindLandMatrix() {\n this->node2Parent = {};\n this->sizeOfSet = {};\n }\n\n void addNode(const int node) {\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\npublic:\n vector<int> parent;\n vector<int> left;\n vector<int> right;\n int find(int a) {\n if(parent[a]==a)\n return a;\n return parent[a] = find(parent[a]);\n }\n void my_union(int a,int b) {\n a = find(a);\n b = find(b);\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class Solution {\npublic:\n vector<int> parent;\n vector<int> left;\n vector<int> right;\n int find(int a) {\n if(parent[a]==a)\n return a;\n return parent[a] = find(parent[a]);\n }\n void my_union(int a,int b) {\n a = find(a);\n b = find(b);\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DisjointSet\n{\n vector<int>rank,parent;\npublic:\n DisjointSet(int N)\n {\n rank.resize(N+1,0);\n parent.resize(N+1);\n for(int i=0;i<=N;i++)\n {\n parent[i]=i;\n }\n }\n\n int findUPar(int Node)\n {\n if(Node==parent[Node])\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DisjointSet\n{\n vector<int>rank,parent;\npublic:\n DisjointSet(int N)\n {\n rank.resize(N+1,0);\n parent.resize(N+1);\n for(int i=0;i<=N;i++)\n {\n parent[i]=i;\n }\n }\n\n int findUPar(int Node)\n {\n if(Node==parent[Node])\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "class DisjointSet\n{\n vector<int>rank,parent;\npublic:\n DisjointSet(int N)\n {\n rank.resize(N+1,0);\n parent.resize(N+1);\n for(int i=0;i<=N;i++)\n {\n parent[i]=i;\n }\n }\n\n int findUPar(int Node)\n {\n if(Node==parent[Node])\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
0
{ "code": "struct DSU {\n int n;\n vector<int> par, sz;\n\n DSU(int n) : par(n), sz(n, 1) {\n for (int i = 0; i < n; i++) {\n par[i] = i;\n }\n }\n\n int find(int a) {\n if (par[a] == a) return a;\n return par[a] = find(par[a]);\n }\n\n void make(int a, int ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n //simple dfs\n bool dfs(int i,int j,vector<vector<int>> &v){\n int n = v.size();\n int m = v[0].size();\n if(i<0 ||j<0||i>=n||j>=m||v[i][j]==-1||v[i][j]==1e6)\n return false;\n if(i==n-1)return true;\n\n v[i][j]=1e6; //for visi...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n\n int ROW, COL;\n\n vector<vector<int>> directions{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n bool isDFSPossible(vector<vector<int>>& temp, int row, int col){\n if(row < 0 || row >= ROW || col >= COL || col < 0 || temp[row][col] == 1){\n return false;\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n\n int ROW, COL;\n\n vector<vector<int>> directions{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n bool isDFSPossible(vector<vector<int>>& temp, int row, int col){\n if(row < 0 || row >= ROW || col >= COL || col < 0 || temp[row][col] == 1){\n return false;\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n\nvector<vector<int>> directions = {{0,1},{0,-1}, {1,0},{-1,0}};\n bool dfs(int r, int c, int row, int col, vector<vector<int>> &mat){\n mat[r][c] = 1;\n if(r==row-1) return true;\n for(auto &dir:directions){\n int dr = r+dir[0];\n in...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n\nvector<vector<int>> directions = {{0,1},{0,-1}, {1,0},{-1,0}};\n bool dfs(int r, int c, int row, int col, vector<vector<int>> &mat){\n mat[r][c] = 1;\n if(r==row-1) return true;\n for(auto &dir:directions){\n int dr = r+dir[0];\n in...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n int dx[8]={1,0,-1,0,1,-1,1,-1};\n int dy[8]={0,-1,0,1,-1,1,1,-1};\n map<pair<int,int>,pair<int,int>> parent;\n map<pair<int,int>,int> minj;\n map<pair<int,int>,int> maxj;\n\n pair<int,int> find(pair<int,int> p){\n if(parent[p]==p)\n return p;\...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "// Hay\nvoid printArr(const vector<bool> & arr){\n for(int i = 0 ; i < arr.size() ; i ++) cout<<arr[i]<<\" \";\n cout<<endl;\n}\nvoid printArr(const vector<int> & arr){\n for(int i = 0 ; i < arr.size() ; i ++) cout<<arr[i]<<\" \";\n cout<<endl;\n}\nvoid printArr(const vector<vector<bool>> & arr...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n int latestDayToCross(int row, int col, vector<vector<int>>& cells) {\n int left = 1, right = cells.size(), ans = 0;\n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (canWalk(cells, row, col, mid)) {\n ans...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
1
{ "code": "class Solution {\npublic:\n int latestDayToCross(int row, int col, vector<vector<int>>& cells) {\n int left = 1, right = cells.size(), ans = 0;\n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (canWalk(cells, row, col, mid)) {\n ans...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool isPossible(int m, int n, int t, vector<vector<int>>& cells) {\n vector<vector<int>> grid(m + 1, vector<int>(n + 1, 0));\n vector<pair<int, int>> directions {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\n for (int i = 0; i < t; i++) {\n grid[cells[...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool isPossible(int m, int n, int t, vector<vector<int>>& cells) {\n vector<vector<int>> grid(m + 1, vector<int>(n + 1, 0)); // Grid representation\n vector<pair<int, int>> directions {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; // Possible directions\n\n for (int...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool check(int mid, int row, int col, vector<vector<int>>& cells){\n vector<vector<int>> mat(row,vector<int> (col,0));\n for(int i=0;i<=mid;i++){\n mat[cells[i][0]-1][cells[i][1]-1]=1;\n }\n queue<pair<int,int>> q;\n for(int i=0;i...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "\nclass Solution {\npublic:\n int latestDayToCross(int row, int col, vector<vector<int>>& cells) {\n vector<vector<int>> mt0(row, vector<int>(col, 0));\n\t\tvector<vector<int>> d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n\t\tauto poss = [&](int mxd) -> bool {\n\t\t\tvector<vector<int>> mt = mt0;\n\t...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n \n bool findpath(int n, int m, vector<vector<int>>& v, int mid)\n {\n queue<pair<int, int>> q;\n vector<vector<int>> vis(n,vector<int>(m,0));\n \n for(int i = 0; i < mid; i++)\n {\n vis[v[i][0]-1][v[i][1]-1] = 1;\n }\...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "/////////////////////////////// Preface\n// utility functions\nusing ll = long long;\nusing ld = long double;\nusing ull = unsigned long long;\n\n// typedef\ntypedef pair<int, int> pii;\ntypedef pair<ll, ll> pll;\ntypedef tuple<int, int, int> ti3;\ntypedef tuple<int, int, int, int> ti4;\ntypedef tuple<int,...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class DSU {\n vector<int> parent; // necessary\n vector<int> rank;// is this just for more balanced and efficient dsu\npublic:\n DSU(int n){\n parent.resize(n);\n rank.resize(n);\n for(int i=0; i<n; i++){\n parent[i] = i;\n rank[i] = 1;\n }\n }\...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "// bfs + binary search\n// binary search: O(log n)=O(log(2*1e4))=4\n// moi check ok() -> bfs: O(m*n)=2.1e4\n// => O(1e4)\nclass Solution {\npublic:\n int row,col;\npublic:\n int latestDayToCross(int r, int c, vector<vector<int>>& a) {\n //TTTTFFFF (T co duong di tu top top toi end at day i, F:...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool isPossible(vector<vector<int>>m) {\n vector<vector<int>> dir = {{1,0},{0,1},{-1,0},{0,-1}};\n\n queue<pair<int,int>>q;\n\n for(int i=0;i<m[0].size();i++) {\n if(m[0][i]==0) {\n q.push({0,i});\n }\n }\n\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "typedef long long int ll;\nconst ll INF = 1e12;\nmap<pair<int,int>,int> mp;\nclass Solution {\nprivate:\n bool possible(ll day,int row,int col){\n queue<pair<int,int>> q;\n vector<vector<bool>> visited(row,vector<bool>(col,false)); \n for(int i = 0;i < col;i++){\n visited...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n map<pair<int,int>,int>mp;\n bool check(int mid,vector<vector<int>>&cells,int &row,int &col)\n {\n queue<pair<int,int>>qu;\n vector<vector<int>>vis(row+1,vector<int>(col+1,0));\n for(int i=1;i<=col;i++) if(mp[{1,i}]>mid) qu.push({1,i});\n whil...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n int R;\n int C;\n bool reach(vector<vector<bool>>& Graph,int i,int j){\n if(min(i,j)<0 || i>=R || j>=C){\n return false;\n }\n if(Graph[i][j]){\n return false;\n }\n if(i==R-1){\n return true;\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool solve(vector<vector<int>>&matrix,int i,int j,vector<vector<int>>&dp){\n if(j<0 || j>=matrix[0].size() || i<0 ) return false;\n if(i>=matrix.size()) return true; \n if(matrix[i][j]==1) return false;\n if(dp[i][j]!=-1) return dp[i][j];\n\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool solve(vector<vector<int>>&matrix,int i,int j,vector<vector<int>>&dp){\n if(j<0 || j>=matrix[0].size() || i<0 ) return false;\n if(i>=matrix.size()) return true; \n if(matrix[i][j]==1) return false;\n if(dp[i][j]!=-1) return dp[i][j];\n\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n int d[5] = {-1,0,1,0,-1};\n bool dfs(int i, int j, vector<vector<int>> &grid, vector<vector<bool>> &visited, int row, int col){\n // cout<<i<<\" \"<<j<<endl;\n if(i == row - 1){\n return true;\n }\n visited[i][j]=true;\n bool a...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n int dir[5] = {1, 0, -1, 0, 1};\n\n bool bfs(int startj, vector<vector<int>> &grid, int row, int col, vector<vector<int>> &vis)\n {\n int start = 0 * col + startj; // (0, startj)\n queue<int> q;\n q.push(start);\n while(!q.empty())\n {\...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool solve(int m, vector<vector<int>>& cells, int r, int c) {\n // Create a matrix and mark blocked cells\n vector<vector<int>> mat(r, vector<int>(c, 0));\n for (int i = 0; i < m; i++) {\n mat[cells[i][0] - 1][cells[i][1] - 1] = 1;\n }\n...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool dfs(int row, int col, vector<vector<bool>>& visited, vector<vector<bool>>& land, int u, int v) {\n if (v>=1 && land[u][v-1]) { \n bool visit = !visited[u][v-1];\n visited[u][v-1] = true;\n if (visit && dfs(row,col,visited,land,u,v-1)) return true;...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
2
{ "code": "class Solution {\npublic:\n bool bfs(vector<vector<bool>>& grid,int m, int n) {\n vector<vector<bool>> visited(m,vector<bool>(n,true));\n queue<pair<int, int>> que;\n for(int j=0; j<n; j++) {\n if(grid[0][j]) {\n que.push({0,j});\n visited[0][...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\n int dx[4] = {-1,0,1,0};\n int dy[4] = {0,1,0,-1};\n bool possible(int row, int col, vector<vector<int>>& cells, int op){\n vector<vector<int>> grid(row,vector<int>(col,0));\n vector<vector<int>> distance(row,vector<int>(col,INT_MAX));\n for(int i=0;...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> possiblePaths = {{1,0},{0,1},{-1,0},{0,-1}};\n int latestDayToCross(int row, int col, vector<vector<int>>& cells) {\n int start=0;\n int end=cells.size() - 1;\n int ans=-1;\n while(start<=end){\n int mid = start + (end...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\n inline int pair2int(const pair<int, int>& p, int c) const {\n return p.first*c + p.second;\n }\n\n bool in_bounds(int x, int y, int m, int n){\n return x >= 0 && y >= 0 && x < m && y < n;\n }\n\n bool possible_to_cross(int row, int col, int t, const ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\n bool dfs(int row, int col, vector<vector<bool>>& visited, vector<vector<bool>>& land, int u, int v) {\n if (v>=1 && land[u][v-1]) { \n bool visit = !visited[u][v-1];\n visited[u][v-1] = true;\n if (visit && dfs(row,col,visited,land,u,v-1)) return true;...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "#define ll long long\n#define pb push_back\nclass Solution {\npublic:\n void dfs(ll xnode,ll ynode,vector<vector<ll>>& grid,vector<vector<ll>>& vis,ll delx[],ll dely[]){\n ll n = grid.size();\n ll m = grid[0].size();\n for(ll i=0;i<8;i++){\n ll newx = xnode+delx[i];\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "vector<vector<int>> dxdy = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};\n\nclass Solution {\npublic:\n bool canReachEnd(vector<vector<int>>& matrix) {\n int n = matrix.size();\n int m = matrix[0].size();\n queue<pair<int, int>> q;\n vector<vector<bool>> visited(n, vector<bool>(m, fals...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\n int fun(int target, vector<vector<int>> &v1)\n {\n int n = v1.size();\n int m = v1[0].size();\n queue<pair<int,int>> q1;\n\n vector<vector<int>> vis(n,vector<int>(m,-1));\n\n for(int j = 0; j<m; j++)\n {\n if(v1[0][j] > ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\n bool dfs(map<pair<int,int>,int> &mp,int row,int col,int i,int j,map<pair<int,int>,bool> &vis,int mid){\n if(i>row or j>col) return false;\n if ((mp.find({i,j})!=mp.end()) and (mp[{i,j}]<=mid)){\n return false;\n }\n\n ...
2,101
<p>There is a <strong>1-based</strong> binary matrix where <code>0</code> represents land and <code>1</code> represents water. You are given integers <code>row</code> and <code>col</code> representing the number of rows and columns in the matrix, respectively.</p> <p>Initially on day <code>0</code>, the <strong>entire...
3
{ "code": "class Solution {\npublic:\nint n,m;\nbool dfs(int row,int col,set<pair<int,int>> &st){\n if(row == n-1) return true;\n st.insert({row,col});\n int delRow[] = {-1,0,+1,0};\n int delCol[] = {0,+1,0,-1};\n for(int k=0;k<4;k++){\n int nrow = row + delRow[k];\n int ncol = col + del...