id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\nint minDays(vector<int>& bloomday, int m, int k) {\n\tint N = bloomday.size();\n\tvector<int> bloom(N, 0); // continuous bloom flowers\n\tvector<pair<int,int>> vec; // bloomday , idx\n\tfor(int i = 0; i < N; i++) {\n\t\tvec.push_back({bloomday[i], i});\n\t}\n\tsort(vec.begin(),... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\nint minDays(vector<int>& bloomday, int m, int k) {\n\tint N = bloomday.size();\n\tvector<int> bloom(N, 0); // continuous bloom flowers\n\tvector<pair<int,int>> vec; // bloomday , idx\n\tfor(int i = 0; i < N; i++) {\n\t\tvec.push_back({bloomday[i], i});\n\t}\n\tsort(vec.begin(),... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\tint minDays(vector<int>& bloomday, int numbouq, int adjcnt)\n\t{\n\t\tint L = 0;\n\t\tint R = *max_element(bloomday.begin(), bloomday.end()) + 1;\n\t\twhile (L + 1 < R) {\n\t\t\tint mid = (L + R) / 2;\n\t\t\tint cnt = countbouquets(bloomday, adjcnt, mid);\n\t\t\tif (cnt >= numb... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\tint minDays(vector<int>& bloomday, int numbouq, int adjcnt)\n\t{\n\t\tint L = 0;\n\t\tint R = *max_element(bloomday.begin(), bloomday.end()) + 1;\n\t\twhile (L + 1 < R) {\n\t\t\tint mid = (L + R) / 2;\n\t\t\tint cnt = countbouquets(bloomday, adjcnt, mid);\n\t\t\tif (cnt >= numb... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int func(vector<int>&vec, int n, int k){\n stack<int>st;\n int cnt = 0;\n for(int i=0;i<vec.size();i++){\n if(vec[i]<=n){\n st.push(vec[i]);\n }\n if(st.size()==k){\n cnt++;\n w... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& bloomDay, int m, int k) {\n int l=bloomDay.size();\n int low=1e9;\n int high=0;\n for(int i=0;i<l;i++)\n {\n high=max(high,bloomDay[i]);\n low=min(low,bloomDay[i]);\n }\n if(low==1... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int minDays(vector<int>& bloomDay, int m, int k) {\n ll n = bloomDay.size();\n ll w = (ll)m * (ll)k;\n if (w > n) return -1;\n ll low = 0, high = 1e9, ans = 1e9;\n while (low <= high) {\n ll mid = (low + high... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "#define ll long long int\nclass Solution {\n bool isPossible(vector<int> &nums, ll &m, ll &k, ll day){\n\n vector<ll> temp;\n temp.push_back(-1);\n ll n = nums.size();\n for(ll i=0;i<n;i++){\n if(nums[i]>day) temp.push_back(i);\n }\n\n ll res = 0;\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\n int func(vector<int>& arr, int m, int k, int mid){\n int l=0, r=0, n=arr.size();\n deque<int> q;\n //int maxi=-1;\n int count=0;\n // sliding window maximum implementation\n while(r<n){\n if(r-l+1<k){\n // ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\nprivate:\n bool possible(unordered_map<int,int> &hash,int day,int m,int k,int n)\n {\n int i=k-1;\n while(i<n)\n {\n if(hash[i]<=day)\n {\n m--;\n if(i+k<n) i+=k;\n else break; \n }\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\nprivate:\n bool possible(map<int,int> &hash,int day,int m,int k)\n {\n int i=0;\n auto it=hash.begin();\n while(it!=hash.end())\n {\n if(it->second<=day)\n {\n m--;\n int num=k;\n while(it... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\nprivate:\n bool possible(map<int,int> &hash,int day,int m,int k)\n {\n int i=0;\n auto it=hash.begin();\n while(it!=hash.end())\n {\n if(it->second<=day)\n {\n m--;\n int num=k;\n while(it... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n bool checkOk(int val, vector<int>& bloomDay, int m, int k) {\n int countAj = 0;\n int count = 0;\n for (int j = 0; j < bloomDay.size(); ++j) {\n if (bloomDay[j] <= val) {\n countAj++;\n }\n else {\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& bloomDay, int m, int k) {\n if ((long)m*k>bloomDay.size()) return -1;\n if ((long)m*k==bloomDay.size()) return *max_element(bloomDay.begin(),bloomDay.end());;\n set <int> s1(bloomDay.begin(),bloomDay.end());\n vector <int> ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& bloomDay, int m, int k) {\n int n = bloomDay.size();\n\n if (n < (long long)m * k) {\n return -1;\n }\n\n unordered_map<int, int> mp;\n\n for (const auto& d : bloomDay) {\n mp[d]++;\n }\n... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n bool canMakeBouquets(const std::vector<int>& bloomDay, int m, int k, int days) {\n int adj = 0, bouquet = 0;\n for (int bloom : bloomDay) {\n if (bloom <= days) {\n adj++;\n if (adj == k) {\n bouquet++;... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\n\n int f(vector<int>& bloomDay,int k,int dayvalue){ int bouquets=0;\n\n int count=0;\n\n\n for(int i=0;i<bloomDay.size();i++){ \n\n if(bloomDay[i]<=dayvalue){ \n \n count++;\n\n\n }\n\n else {\n\n bouquets+... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\n\n int f(vector<int>& bloomDay,int k,int dayvalue){ int bouquets=0;\n\n int count=0;\n\n\n for(int i=0;i<bloomDay.size();i++){ \n\n if(bloomDay[i]<=dayvalue){ \n \n count++;\n\n\n }\n\n else {\n\n bouquets+... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\n\n int f(vector<int>& bloomDay,int k,int dayvalue){ int bouquets=0;\n\n int count=0;\n\n\n for(int i=0;i<bloomDay.size();i++){ \n\n if(bloomDay[i]<=dayvalue){ \n \n count++;\n\n\n }\n\n else {\n\n bouquets+... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int bouqets(vector<int> bloomDay, int m, int k, int day){\n int ans = 0;\n int adjacentFlowers = k;\n for(int i=0;i<bloomDay.size();i++){\n bloomDay[i] -= day;\n if(bloomDay[i]<=0) adjacentFlowers--;\n else adjacentFlowers... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int countThem(vector<int> arr,int mid , int k)\n {\n int i=0,j=0,count=0;\n while(j<arr.size())\n {\n if(arr[j]>mid)\n {\n j++;\n i=j;\n continue;\n }\n if(j-i+1==... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int bouqets(vector<int> bloomDay, int m, int k, int day){\n int ans = 0;\n int adjacentFlowers = k;\n for(int i=0;i<bloomDay.size();i++){\n bloomDay[i] -= day;\n if(bloomDay[i]<=0) adjacentFlowers--;\n else adjacentFlowers... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int bouqets(vector<int> bloomDay, int m, int k, int day){\n int ans = 0;\n int adjacentFlowers = k;\n for(int i=0;i<bloomDay.size();i++){\n bloomDay[i] -= day;\n if(bloomDay[i]<=0) adjacentFlowers--;\n else adjacentFlowers... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int bouqets(vector<int> bloomDay, int m, int k, int day){\n int ans = 0;\n int adjacentFlowers = k;\n for(int i=0;i<bloomDay.size();i++){\n bloomDay[i] -= day;\n if(bloomDay[i]<=0) adjacentFlowers--;\n else adjacentFlowers... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& bloomDay, int m, int k) {\n int n=bloomDay.size();\n if((double)m*k>n)return -1;\n unordered_set<int>unique_elements(bloomDay.begin(),bloomDay.end());\n vector<int>searchSpace;\n for(auto element:unique_elements){\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\nprivate:\n int count(vector<int>& bloomDay, int k, int day) {\n int res = 0;\n int l = bloomDay.size();\n\n int cnt = 0;\n for (int i = 0; i < l; i++) {\n if (bloomDay[i] <= day) cnt++;\n else cnt = 0;\n\n if (cnt >= k) {\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "\n#pragma GCC optimize(\"Ofast,no-stack-protector\")\n#pragma GCC optimize(\"no-math-errno,unroll-loops\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4\")\n\n#include <new> // For hardware_constructive_interference_size\n\nstatic int speedup = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nu... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int fn(int day,vector<int>& bloomDay, int m, int k, int n) {\n int cur = 0, b = 0;\n for(int i = 0; i < n; i++) {\n if(bloomDay[i]<=day) {\n cur++;\n if(cur==k) {\n cur = 0;\n b++;\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& nums, int m, int k) {\n \n set<int> st;\n for (auto x : nums)\n st.insert(x);\n vector<int> nn(st.begin(), st.end());\n int l = 0, h = nn.size() - 1, ans = -1;\n while (l <= h) {\n int mid =... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\n int flower(vector<int> &bloomDay,int n,int day,int &b,int k)\n {\n int f=0;\n int ct=0;\n for(int i=0;i<n;i++)\n {\n if(bloomDay[i]<=day)\n {\n f++;\n ct++;\n if(ct==k)\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n\n int flower(vector<int> &bloomDay,int n,int day,int &b,int k)\n {\n int f=0;\n int ct=0;\n for(int i=0;i<n;i++)\n {\n if(bloomDay[i]<=day)\n {\n f++;\n ct++;\n if(ct==k)\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int numOfBouquets(vector<int> bloomDay, int mid,int k){\n int numOfBouquets = 0;\n int flowers = 0;\n for(auto d : bloomDay){\n if(d<=mid){\n flowers++;\n if(flowers==k){\n numOfBouquets++;\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\nprivate:\n long long count_bouquet(vector<int> bloomday,int k,int day){\n int n=bloomday.size();\n long long count=0,ans=0;\n for(int i=0;i<n;i++){\n if(bloomday[i]<=day){\n count++;\n }\n else{\n count... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& a, int m, int k) \n {\n int n=a.size();\n multiset<int> s;\n vector<int> b;\n for(int i=0;i<n;i++)\n {\n if(i<(k-1))\n {\n s.insert(a[i]);\n continue;\n ... |
1,605 | <p>You are given an integer array <code>bloomDay</code>, an integer <code>m</code> and an integer <code>k</code>.</p>
<p>You want to make <code>m</code> bouquets. To make a bouquet, you need to use <code>k</code> <strong>adjacent flowers</strong> from the garden.</p>
<p>The garden consists of <code>n</code> flowers, ... | 3 | {
"code": "class Solution {\npublic:\n int minDays(vector<int>& a, int m, int k) \n {\n int n=a.size();\n multiset<int> s;\n vector<int> b;\n for(int i=0;i<n;i++)\n {\n if(i<(k-1))\n {\n s.insert(a[i]);\n continue;\n ... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 0 | {
"code": "class Solution {\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n \n // Auxiliary matrix to store the new state of the board\n vector<vector<int>> newBoard(n, vector<int>(m, 0));\n \n // Directi... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 0 | {
"code": "class Solution {\npublic:\n \n int dirX[8] = {1, -1, 0, 0, +1, -1, +1, -1};\n int dirY[8] = {0, 0, 1, -1 , -1 , 1, 1, -1};\n\n void checkForLiveCell(vector<vector<int>>& board, int i, int j){\n\n int n = board.size();\n int m = board[0].size();\n \n int cnt = 0;\n for(in... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 0 | {
"code": "class Solution {\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n int n = board.size();\n int m = board[0].size();\n \n // Auxiliary matrix to store the new state of the board\n vector<vector<int>> newBoard(n, vector<int>(m, 0));\n \n // Directi... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 0 | {
"code": "class Solution {\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n int m = board.size();\n int n = board[0].size();\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n int sumN = 0;\n if(i+1<m && j+1<n)sumN += board[i+1][j+1]%2;\n ... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 1 | {
"code": "class Solution {\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n int m = board.size(), n = board[0].size();\n vector<vector<int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};\n for(int i = 0; i < m; i++){\n for(int j = 0; j < n... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 1 | {
"code": "class Solution {\n private:\n int solve(int i,int j,vector<vector<int>>& board,int m,int n){\n int count=0;\n if(i+1<m&&j+1<n){\n count+=board[i+1][j+1];\n }\n if(i-1>=0&&j-1>=0){\n count+=board[i-1][j-1];\n }\n if(j-1>=0&&i+1<m){\n ... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 3 | {
"code": "class Solution {\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n vector<vector<int>> copiedBoard = board;\n int m = board.size(), n = board[0].size();\n vector<vector<int>> directions = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1},\n {1, ... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 3 | {
"code": "class Solution {\npublic:\n\n int lnc(vector<vector<int>>& board,int i,int j)\n {\n vector<pair<int,int>>directions={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};\n int live_neigh=0;\n for(auto dir:directions)\n {\n int ni=i+dir.first;\n int... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 3 | {
"code": "class Solution {\nprotected:\n vector<vector<int>> b1;\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n b1 = board;\n int n = board.size(), m = board[0].size();\n for(int i=0; i<n; i++) for(int j=0; j<m; j++) updateCell(board, i, j, n, m);\n }\n\n void updateCell(... |
289 | <p>According to <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">Wikipedia's article</a>: "The <b>Game of Life</b>, also known simply as <b>Life</b>, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."</p>
<p>The board is made up o... | 3 | {
"code": "class Solution {\nprotected:\n vector<vector<int>> b1;\npublic:\n void gameOfLife(vector<vector<int>>& board) {\n b1 = board;\n int n = board.size(), m = board[0].size();\n for(int i=0; i<n; i++) for(int j=0; j<m; j++) updateCell(board, i, j, n, m);\n for(int i=0; i<n; i++... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "#include <algorithm>\n#include <array>\n#include <string>\n#include <string_view>\n#include <unordered_set>\n#include <utility>\n\nclass Solution {\npublic:\n bool wordPattern(std::string pattern, std::string s) {\n std::array<std::string_view, 26> fwd_map;\n std::unordered_set<std::string... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n unordered_map<char, string>mapping;\n unordered_map<char, bool>found;\n int n = pattern.length();\n int len = s.length();\n\n int j=0;\n\n for(int i=0;i<n;i++) {\n string word ... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n std::unordered_map<std::string_view, char> um;\n int was[26] = {0};\n int first = 0, second = 0;\n int word_id = 0;\n for (int i = 0; i <= s.size(); ++i) {\n if (s[i] == ' ' || i == i... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n unordered_map<char, string> map; //<pattern, s>\n string temp;\n vector<string> word;\n for (int i = 0; i <= s.length(); i++) {\n if (i == s.length() || s[i] == ' ') {\n word.... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n unordered_map<char, string> mapp; //<pattern, s>\n string temp;\n int j = 0;\n for (int i = 0; i <= s.length(); i++) {\n if (s[i] == '\\0' || s[i] == ' ') {\n if(pattern[j] ==... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n unordered_map<string, char> word_to_letter;\n vector<int> used(26);\n\n string word = \"\";\n int curr_letter = 0;\n\n for(int i=0; i<s.size(); i++){\n if(s[i] == ' ' || i == s.size()... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n unordered_map<unsigned long, char> hashmap;\n unordered_map<char, unsigned long> hashmap2;\n unsigned long hash = 5381;\n int beg = 0;\n int end = 0;\n int count;\n for(count = 0; count < pattern.length(); ... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n vector<string> v(26,\"\");\n set<string> seen;\n stringstream ss(s);\n string word;\n int n = pattern.size();\n int i = 0;\n while(ss>>word){\n if(i==n) return false;\n ... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n unordered_map<char,string> p;\n unordered_map<string,char> q;\n string word=\"\";\n int j=0;\n for(int i=0;i<s.length();i++){\n if(s[i]==' '){\n if(p.count(pattern[j]))... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 0 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n map<char, string> pmap;\n map<string, char> smap;\n vector<string> words;\n stringstream ss(s); \n string word;\n \n while (ss >> word) {\n words.push_back(word);... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 1 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n int pattern_len = pattern.size(), s_len = s.size();\n\n vector<char> patterns;\n for (int i = 0; i < pattern_len; i++) patterns.push_back(pattern[i]);\n vector<string> strings;\n for (int i = 0;... |
290 | <p>Given a <code>pattern</code> and a string <code>s</code>, find if <code>s</code> follows the same pattern.</p>
<p>Here <b>follow</b> means a full match, such that there is a bijection between a letter in <code>pattern</code> and a <b>non-empty</b> word in <code>s</code>. Specifically:</p>
<ul>
<li>Each lette... | 1 | {
"code": "class Solution {\npublic:\n bool wordPattern(string pattern, string s) {\n s=s+' ';\n unordered_map<string,char>mp1;\n unordered_map<char,string>mp2;\n string temp=\"\";\n int ind=0;\n for(auto i:s){\n if(i==' '){\n if(mp1.count(temp)>0 ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n for(int i=0; i<n; i++) {\n //cout << i << endl;\n while(nums[i] != nums[nums[i]-1] && nums[i] != i+1) {\n //cout<<nums[i]<<endl;\n int tmp = nums[... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int slow = 0, fast = 0;\n\n while(true)\n {\n slow = nums[slow];\n fast = nums[nums[fast]];\n if(slow == fast)\n break;\n }\n\n int temp = 0;\n w... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();//\n int i=0;\n while(i<n)\n {\n int crt=nums[i]-1;\n if(nums[i]==i+1)i++;\n else if(nums[i]!=nums[crt])swap(nums[i],nums[crt]);\n else i++;\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n for(int i=0;i<nums.size();i++){\n if(nums[i]<0){\n int n=nums[i]*-1;\n if(nums[n]<0){\n return n;\n }\n else{\n nums[n]... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int slow = nums[0];\n int fast = nums[0];\n\n while(true){\n slow = nums[slow];\n fast = nums[nums[fast]];\n if(fast==slow){\n break;\n }\n }\n\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n for(int i=0;i<n;i++)\n {\n int index=nums[i]%n;\n nums[index]+=n;\n }\n for(int i=0;i<n;i++)\n {\n int val=nums[i];\n if(val/n>=... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n for(int i = 0; i < nums.size(); i++){\n int idx = abs(nums[i]) - 1;\n if(nums[idx] < 0) return abs(nums[i]);\n else nums[idx] = -1*nums[idx];\n }\n return -1;\n }\n};",
"memory... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 0 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n // int n= nums.size();\n \n // for(int i=0; i<n; i++){\n // for(int j=i+1; j<n; j++){\n // if(nums[i]==nums[j]){\n // return nums[i];\n // };\n // };\n // };\n // re... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 1 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int slow=nums[0];\n int fast=nums[slow];\n while(fast!=slow){\n fast = nums[nums[fast]];\n slow = nums[slow];\n }\n int s=0 ;\n while(s!=fast){\n s=nums[s];\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 1 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int tortoise = nums[0];\n int hare = nums[0];\n \n do {\n tortoise = nums[tortoise];\n hare = nums[nums[hare]];\n } while (tortoise != hare);\n \n tortoise = nums[0... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n vector<bool> vis(n+1, false);\n\n for(auto num:nums){\n if(vis[num]){\n return num;\n }\n vis[num] = true;\n }\n\n return -1;\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n vector<bool> visit(n,false);\n for(int i:nums){\n if(visit[i]==false) visit[i] = true;\n else\n return i;\n }\n return -1;\n }\n};",
"m... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int vis[nums.size()];\n\n for(int i = 0; i < nums.size(); i++) {\n vis[i] = 0;\n }\n\n for(int i = 0; i < nums.size(); i++) {\n if(vis[nums[i]] == 1) {\n return nums[i];\... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int a[100000]={0};\n for(int i=0;i<nums.size();i++){\n a[nums[i]-1]++;\n }\n for(int i=0;i<100000;i++){\n if(a[i]>1){\n return i+1;\n }\n }\n ret... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int a[100000]={0};\n for(int i=0;i<nums.size();i++){\n a[nums[i]-1]++;\n }\n for(int i=0;i<100000;i++){\n if(a[i]>1){\n return i+1;\n }\n }\n ret... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int ans;\n int hash[100001]={0};\n for(int i=0;i<nums.size();i++){\n hash[nums[i]]+=1;\n }\n for(int i=0;i<nums.size();i++){\n if(hash[nums[i]]>1){\n ans=nums[i];\... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(const vector<int>& nums) {\n vector<char> seen(nums.size(), 0);\n for (auto x : nums) {\n if (std::exchange(seen[x], true)) return x;\n }\n return -1; \n }\n};",
"memory": "27694"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n bool* check = new bool[nums.size()+1];\n for(int i = 1; i < nums.size()+1; i++){\n check[i] = false;\n }\n for(auto it : nums){\n if(check[it]) return it;\n check[it] = true;... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int num=-1;\n\n // for(int i=0; i<nums.size(); i++){\n // for(int j=i+1; j<nums.size(); j++){\n // if(nums[i]==nums[j]){\n // num = nums[i];\n // break;\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int n = nums.size();\n for(int i=0;i<n-1;i++){\n if(nums[i]==nums[i+1]) return nums[i];\n }\n return 0;\n }\n};",
"memory": "31058"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n for(int i = 1; i < nums.size(); i++) {\n if(nums[i] == nums[i-1]) return nums[i];\n }\n return -1;\n }\n};",
"memory": "31058"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n // 1 2 2 3 4\nint ans=-1;\n for(int i=0;i<nums.size()-1;i++)\n {\n if(nums[i]==nums[i+1]){\n ans= nums[i];\n break;\n }\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n // int duplicatenumber(vector<int> &nums){\n // int i,j;\n // int n= nums.size();\n // while(i< n){\n // for(int i=0; i<=n; i++){\n // for(int j=i+1; j<=n; j++){\n // if(nums[i]==nums[j]){\n // return nu... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n\n for(int i = 0; i < n-1; i++){\n if(nums[i] == nums[i+1]){\n return nums[i];\n }\n }\n return -1;\n }\... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n for(int i=1;i<nums.size();i++){\n if(nums[i-1]==nums[i]){\n return nums[i];\n }\n }\n return nums[0];\n }\n};",
"memory": "33300"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n for(int i;i<nums.size();i++){\n if(nums[i]==nums[i+1]){\n return nums[i];\n }\n }\n return -1;\n \n \n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n sort(nums.begin(),nums.end());\n for(int i=1;i<n;i++){\n if(nums[i-1]==nums[i]){\n return nums[i];\n }\n \n \n }\n retur... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size()-1;i++){\n if(nums[i]==nums[i+1]){\n return nums[i];\n }\n }\n return -1;\n }\n};",
"memory": "35543"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 2 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n for(int i = 1 ; i < nums.size(); i++)\n {\n if(nums[i-1] == nums[i])\n {\n return nums[i];\n }\n }\n\n return 0;}\n};",
"memory": "35543"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int size=nums.size();\n int value;\n int arr[size];\n for(int i=0;i<size;i++)\n {\n arr[i]=nums[i];\n \n }\n sort(arr,arr+size);\n for(int i=0;i<size;i++)\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n int arr[n];\n for(int i = 0 ; i < n ; i++){\n arr[i] = nums[i]; \n }\n sort(arr , arr+n);\n for(int i = 0 ; i < n-1 ; i++){\n if(arr[i] == arr[i +1]... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int ans = 0;\n sort(nums.begin(),nums.end());\n int vecsize = nums.size();\n // Initializing the maximum array\n // cout<<nums[vecsize -1] + 1;\n int dup[nums[vecsize -1] + 1];\n for(int... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n vector<int>temp(n+1,0);\n for(int i=0;i<nums.size();i++){\n temp[nums[i]-1]++;\n }\n for(int i=0;i<temp.size();i++){\n if(temp[i]>=2)return i+1;\n }\n... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n //approch 1: sort\n // int ans=0;\n // sort(nums.begin(),nums.end());\n // for(int i=1;i<nums.size();i++){\n // if(nums[i]==nums[i-1]){\n // ans=nums[i];\n // break;\... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n \n int n=nums.size();\n\n vector<int>ans(n,0);\n\n for(int i=0;i<n;i++){\n\n ans[nums[i]]++;\n\n }\n\n for(int i=0;i<ans.size();i++){\n\n if(ans[i]>=2){\n\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n = nums.size();\n vector<int> count(n+1, 0);\n\n for(int i = 0; i < n; i++){\n count[nums[i]]++;\n if(count[nums[i]] > 1){\n return nums[i];\n } \n }\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n\n int n = nums.size();\n vector<int> frq(n+1,0);\n for(int i=0;i<n;i++){\n if(frq[nums[i]]==0){\n frq[nums[i]]+=1;\n }else {\n return nums[i];\n }\n ... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int> n) {\n sync;\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n \n sort(n.begin(),n.end());\n\n for(int i=0;i<n.size();i++){\n if(n[i]==n[i+1]){\n return n[i];\n }... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int> nums) {\n sort(nums.begin(),nums.end());\n for(int i = 0 ; i < nums.size()-1; i++ ){\n if(nums[i] == nums[i+1]){\n return nums[i];\n }\n }\n return 0;\n }\n};",
"memory": "4787... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int n=nums.size();\n vector<int> arr(nums.begin(),nums.end());\n sort(arr.begin(),arr.end());\n for(int i=0;i<n-1;i++){\n if(arr[i]==arr[i+1])\n return arr[i];\n }\n r... |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n vector<int> V=nums;\n sort(V.begin(),V.end());\n for(int i=0;i<V.size()-1;i++){\n if(V[i]==V[i+1]) return V[i];\n }\n return V[V.size()-1];\n }\n};",
"memory": "50119"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n vector<int> V=nums;\n sort(V.begin(),V.end());\n for(int i=0;i<V.size()-1;i++){\n if(V[i]==V[i+1]) return V[i];\n }\n return V[V.size()-1];\n }\n};",
"memory": "50119"
} |
287 | <p>Given an array of integers <code>nums</code> containing <code>n + 1</code> integers where each integer is in the range <code>[1, n]</code> inclusive.</p>
<p>There is only <strong>one repeated number</strong> in <code>nums</code>, return <em>this repeated number</em>.</p>
<p>You must solve the proble... | 3 | {
"code": "class Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n int i=0,c=0;\n vector<int> v=nums;\n sort(v.begin(),v.end());\n while(i!=(v.size()-1)){\n if(v[i]==v[i+1]){\n c=v[i];\n break;\n }\n i++;\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.