id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "/*\n n is number of jobs\n\n max jobDifficulty table: mjt[i][j] means max jobDifficulty in range[i , j]\n\n dp[i][j]: means the minimum difficulty of a job schedule, if we finished 0 to j-th jobs on 0 to i-th day. (j >= i)\n \n dp[i][j] = dp[i-1][j-k] + max one in jobDifficulty [j-k+1, j] (1...
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "class Solution {\npublic:\n int minDifficulty(vector<int>& jobDifficulty, int d) {\n int n=jobDifficulty.size();\n if(d>n) return -1;\n vector<vector<int>> dp (n, vector<int> (d+1,0));\n vector<vector<int>> maxV (n, vector<int> (n,0));\n for(int i=0;i<n;i++){\n ...
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "/*\n n is number of jobs\n\n max jobDifficulty table: mjt[i][j] means max jobDifficulty in range[i , j]\n\n dp[i][j]: means the minimum difficulty of a job schedule, if we finished 0 to j-th jobs on 0 to i-th day. (j >= i)\n \n dp[i][j] = dp[i-1][j-k] + max one in jobDifficulty [j-k+1, j] (1...
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n/* Macros {{{ */\n/* A lot of this is from some of Benq's submissions\n [https://codeforces.com/profile/Benq]\n Ugly af to the eyes, but with vim fold its barable\n Hopefully c++20 concepts can make all this stuff must cleaner */\n\n/* Basics {{{ ...
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "class Solution {\npublic:\n long long dp[1000][1000];\n int solve(int index , vector<int> &nums , int n , int cnt , int d)\n {\n // base case\n if(index >= n)\n {\n if(cnt == d)\n {\n return 0;\n }\n else\n ...
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "class Solution {\npublic:\n int minDifficulty(vector<int>& jobDifficulty, int d) {\n\n if( d > jobDifficulty.size() )\n return -1;\n\n vector< vector<long int> > maxCost( jobDifficulty.size() + 1, vector<long int>( jobDifficulty.size() + 1 , 0 ) );\n\n for( int i = 1 ; i ...
1,457
<p>You want to schedule a list of jobs in <code>d</code> days. Jobs are dependent (i.e To work on the <code>i<sup>th</sup></code> job, you have to finish all the jobs <code>j</code> where <code>0 &lt;= j &lt; i</code>).</p> <p>You have to finish <strong>at least</strong> one task every day. The difficulty of a job sch...
3
{ "code": "class Solution {\npublic:\n int minDifficulty(vector<int>& jobDifficulty, int d) {\n // find a d partition of the jobDifficulty array to minimize the sum of the max of each subarray\n vector<int>& jd = jobDifficulty;\n int N = jd.size();\n if(N<d)\n return -1;\n ...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
0
{ "code": "class Solution {\npublic:\n int searchForSoldiers(vector<int>& m) {\n int l = 0;\n int h = m.size() - 1;\n while (l <= h) {\n int mid = l + (h - l) / 2;\n if (m[mid] == 0)\n h = mid - 1;\n else\n l = mid + 1;\n }\...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
0
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n vector<pair<int,int>> soldiersCountRow;\n vector<int> ans;\n int row = mat.size(), col = mat[0].size();\n\n for(int i=0; i<row; i++){\n int cnt = -1, start=0, end=col-1;\n\n ...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
0
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n vector<pair<int,int>>v;\n vector<int>ans;\n for(int i=0;i<mat.size();i++)\n {\n int sum=0;\n for(int j=0;j<mat[i].size();j++)\n {\n sum=su...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
0
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n // Vector to store the number of soldiers and the corresponding row index\n vector<pair<int, int>> soldierCount;\n \n // Iterate through each row of the matrix\n for (int i ...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
1
{ "code": "class row\n{\n public:\n int idx;\n int count;\n\n row(int count,int idx)\n {\n this->idx = idx;\n this->count = count;\n } \n\n bool operator < (const row& obj) const\n {\n if(this->count == obj.count)\n {\n return this->idx >obj.idx;\n ...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
1
{ "code": "class Solution {\npublic:\n #define pii pair<int,int>\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n \n \tpriority_queue<pii, vector<pii>, greater<pii>> pq;\n\n\tint n = mat.size();\n\tint m = mat[0].size();\n\n\tint count = 0;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tc...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
2
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n priority_queue<pair<int,int>> pq;\n int len = mat.size();\n for(int i=0;i<len;i++){\n int cnt = count(mat[i].begin(),mat[i].end(),1);\n pq.push({cnt,i});\n if(p...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
2
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n set<pair<int,int>>s;\n for(int i=0;i<mat.size();i++)\n {\n int count=0;\n for(int j=0;j<mat[i].size();j++)\n {\n if(mat[i][j]==1)\n {\...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n map<int,vector<int>> m;\n int ct=0;\n for(int i=0;i<mat.size();i++)\n {\n int ct=0;\n for(int j=0;j<mat[i].size();j++)\n {\n if(mat[i][j]=...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
3
{ "code": "class Solution {\npublic:\nbool cmp(pair<int, int>& a, pair<int, int>& b) {\n if(a.second==b.second)\n {\n return a.first < b.first;\n }\n return a.second < b.second;\n }\n\n //sort by value\n vector<pair<int, int>> sort(map<int, int>& M) {\n // Declare vector of pair...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
3
{ "code": "class Solution {\npublic:\n \n int binary(vector<int> m)\n {\n int l = 0;\n int h = m.size()-1;\n while(l <= h)\n {\n int mid = l + (h-l)/2;\n if(m[mid] == 0)\n h = mid - 1;\n else\n l = mid + 1;\n }\...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
3
{ "code": "class Solution {\npublic:\nstatic bool comp(pair<int,int>a,pair<int,int>b){\n return a.first==b.first?a.second<b.second:a.first<b.first;\n}\nstatic int bs(vector<int>arr){\n int low=0;\n int high=arr.size()-1;\n int ans=-1;\n while(low<=high){\n int mid=(low+high)/2;\n if (arr[...
1,463
<p>You are given an <code>m x n</code> binary matrix <code>mat</code> of <code>1</code>&#39;s (representing soldiers) and <code>0</code>&#39;s (representing civilians). The soldiers are positioned <strong>in front</strong> of the civilians. That is, all the <code>1</code>&#39;s will appear to the <strong>left</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<int> kWeakestRows(vector<vector<int>>& mat, int k) {\n int n = mat.size();\n int m = mat[0].size();\n \n vector<pair<int,int>> soldiers(n);\n \n int i = 0;\n for(auto it : mat){\n for(int j = 0; j<m; j++){\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int mx = *max_element(arr.begin(), arr.end());\n int cnt[mx + 1];\n memset(cnt, 0, sizeof(cnt));\n for (int& x : arr) {\n ++cnt[x];\n }\n sort(cnt, cnt + mx + 1, greater<int>());\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int mx = *max_element(arr.begin(), arr.end());\n int cnt[mx + 1];\n memset(cnt, 0, sizeof(cnt));\n for (int& x : arr) {\n ++cnt[x];\n }\n sort(cnt, cnt + mx + 1, greater<int>());\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n int res = 0;\n sort(arr.begin(), arr.end());\n vector<int> buf = vector<int>();\n int count = 1;\n for (int i = 0; i < n - 1; i++) {\n if (arr[i + 1] == arr[i]) {\n...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n sort(arr.begin(), arr.end());\n int ct = 1;\n priority_queue<int> pq;\n for (int i = 1; i < n; i++) {\n if (arr[i] != arr[i-1]) {\n pq.push(ct);\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n array<int, 100001> freq{0};\n auto [mn_it, mx_it] = minmax_element(arr.begin(), arr.end());\n for (auto num : arr) {\n ++freq[num];\n }\n vector<int> amount;\n for (int num = *mn_it; num...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n static constexpr const size_t theSize{100'001};\n const auto n=int(size(arr));\n if(n<3)return 1;\n using tuple_t=typename std::tuple<int,int>;\n #define g0 get<0>\n #define g1 get<1>\n #def...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n array<int, 100001> freq{0};\n auto [mn_it, mx_it] = minmax_element(arr.begin(), arr.end());\n for (auto num : arr) {\n ++freq[num];\n }\n vector<int> amount;\n for (int num = *mn_it; num...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n int f[100000+1]={0};\n for(int&i:arr){\n f[i]++;\n }\n priority_queue<int> pq; \n for(int& i:f){\n if(i!=0)pq.push(i);\n }\n int res=0;\n int ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n_half = arr.size()/2;\n int min_value = arr[0], max_value = arr[0];\n for (auto const& val: arr) {\n min_value = min(min_value, val);\n max_value = max(max_value, val);\n }\n\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n int maxi=0;\n for(int i=0;i<n;i++){\n if(arr[i]>maxi){\n maxi=arr[i];\n }\n }\n vector<int>frequency(maxi+1,0);\n for(int i=0;i<n;i++){\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n\n int M = 0;\n\n for (int i = 0; i < arr.size(); i++)\n M = max(M, arr[i]);\n\n vector<int> cnt(M + 1, 0);\n\n for (int i = 0; i < arr.size(); i++)\n cnt[arr[i]...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int ans = 0, rc = 0;\n int maxval = *max_element(arr.begin(), arr.end());\n vector<int> freq(maxval + 1);\n for (int a: arr)\n ++freq[a];\n sort(freq.begin(), freq.end(), greater<int>());\n\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int maxElem = *max_element(arr.begin(), arr.end());\n\n vector<int>count(maxElem);\n\n for (int n : arr) {\n count[n-1]++;\n }\n\n sort(count.begin(), count.end(), greater<int>());\n int...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n sort(arr.begin(),arr.end());\n priority_queue<pair<int,int>>pq;\n int c=0,n_size=arr.size();\n int i=0,j=0;\n while(i<n_size){\n c=0,j=i;\n while(j<n_size && arr[i]==arr[j]){\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n static bool comp(pair<int,int> &a, pair<int,int> &b){\n return a.second>b.second;\n }\n\n int minSetSize(vector<int>& arr) {\n int size=arr.size();\n vector<pair<int,int>> ans;\n sort(arr.begin(),arr.end());\n int count=0;\n \n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n sort(arr.begin(), arr.end());\n vector<int> counts;\n\n int currentRuns = 1;\n\n for (int i = 1; i < arr.size(); i++) {\n if (arr[i] == arr[i - 1]) {\n currentRuns += 1;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n sort(arr.begin(), arr.end());\n vector<int> counts;\n\n int currentRuns = 1;\n\n for (int i = 1; i < arr.size(); i++) {\n if (arr[i] == arr[i - 1]) {\n currentRuns += 1;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n std::sort(arr.begin(), arr.end());\n\n std::vector<int> counts;\n int count = 1;\n for (size_t i = 1; i < arr.size(); i++) {\n if (arr[i - 1] == arr[i]) {\n count++;\n } else...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n int ans = 0;\n int mx = arr[0];\n\n for(int i=1;i<arr.size();i++){\n mx = max(mx,arr[i]);\n }\n\n vector<int> f(mx+1);\n\n for(int i=0;i<arr.size();i++){\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "#pragma GCC optimize (\"O3,unroll-loops\")\n#pragma GCC target (\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\n#define pii pair<int,int>\n\nclass Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n\n vector<int> counts (*max_element(arr.b...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:bool static comp(int a, int b)\n{\n return a>b;\n}\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n vector<int>freq(100001,0);\n for(int i=0;i<arr.size();i++)\n {\n freq[arr[i]]++;\n }\n sort(freq.begin(),freq.end...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n sort(arr.begin(),arr.end());\n int st=arr[0];\n int end=arr[arr.size()-1];\n vector<int> hash(end+1,0);\n for(int i=0;i<arr.size();i++){\n hash[arr[i]]++;\n }\...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n vector<int> freq(1e5+5,0);\n for(auto x:arr) freq[x]++;\n sort(freq.begin(),freq.end(),greater<int>());\n int sum=0;\n int i=0;\n while(sum<(n+1)/2) {sum+=freq[i];i++;}\n...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n\nint n=arr.size()/2;\n vector<int> vis(100001,0);\n for(int i=0;i<arr.size();i++)\n {\n vis[arr[i]]++;\n }\n\n sort(vis.begin(),vis.end(),greater<int>());\n\nint sum=0;\nint a=0;\n for(int...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n vector<int> count(100001, 0);\n for(int& i : arr) {count[i]++;}\n sort(count.begin(), count.end());\n int n = arr.size()/2;\n int removed{0};\n int retVal{0};\n int i = count.size()-1;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n vector<int>v(100001, 0);\n int half = ceil(arr.size() / 2.0);\n int ans = 0;\n int count = 0;\n for (int& x : arr)v[x]++;\n sort(v.begin(), v.end...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n vector <int> a(100005);\n int n=arr.size();\n for(int i=0;i<n;i++){\n a[arr[i]]++;\n }\n sort(a.rbegin(),a.rend());\n int total=0;\n for(int i=0;i<n;i++){\n total+=a[i]...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n vector<int> freq(100001,0);\n for(int i : arr){\n freq[i]++;\n }\n sort(freq.rbegin(),freq.rend());\n int s = n;\n int i = 0 ;\n while(s > n/2){\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n\n vector<int>a(100005);\n for(int i=0; i<n; i++){\n a[arr[i]]++;\n }\n sort(a.rbegin(), a.rend());\n int total = 0;\n\n for(int i=0; i<n; i++){\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n vector<int> f(100001, 0);\n for(auto u : arr)\n f[u]++;\n sort(f.rbegin(), f.rend());\n int s = 0 , a = 0;\n for(int i=0;i<f.size();i++) {\n s+=f[i];\n if(s*2 >= arr.size(...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n Solution() {\n // ios::sync_with_stdio(0);\n // cin.tie(0);\n // cout.tie(0);\n }\n\n int minSetSize(vector<int>& arr) {\n // here we can use hash map instead\n vector<int> temp(100001);\n\n for (int i = 0; i < arr.size(); i++) ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n\n Solution(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n\n\n int minSetSize(vector<int>& arr) {\n\n vector<int>temp(100001);\n\n for(int i = 0;i < arr.size();i++){\n temp[arr[i]]++;\n }\n\n in...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n\n Solution(){\n // ios::sync_with_stdio(0);\n // cin.tie(0);\n // cout.tie(0);\n }\n\n\n int minSetSize(vector<int>& arr) {\n\n vector<int>temp(100001);\n\n for(int i = 0;i < arr.size();i++){\n temp[arr[i]]++;\n }\n\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n int count=0;\n vector<int> v(100001);\n for(auto val:arr){\n v[val]++;\n }\n int tcount=0;\n priority_queue<int> pq;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n int limit = arr.size(), count = 0, half = limit / 2, sum = 0;\n\n#if 0\n //1.選擇m_map(這題值的range比較大)\n unordered_map<int,int> m_map;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n set<int> st;\n int n = arr.size();\n int mx = INT_MIN;\n for (int i = 0; i < n; i++) mx = max (mx , arr[i]);\n // map <int , int> mp;\n // for (int i: arr) mp[i]++; \n vector <int> v(mx+1,0)...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int N = 1e5 + 10;\n int minSetSize(vector<int>& arr) {\n vector<int> cnt(N);\n for(int& x : arr) cnt[x]++;\n int n = arr.size();\n int min_req = n / 2;\n if(n & 1) min_req++;\n vector<int> v;\n for(int& p : cnt) {\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int, int> counter;\n for (int e : arr) {\n ++counter[e];\n }\n \n sort(arr.begin(), arr.end(), [&](int l, int r) {\n if (counter[l] == counter[r]) {\n re...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int ans = 0;\n // count frequency of ints\n int m = 0;\n unordered_map<int, int> F;\n for (int &n: arr) {\n m = max(m, ++F[n]);\n }\n // count freqnecy of frequencies\n int...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic: /* // Complexity: O(nlogn) Space: O(n)\n int minSetSize(vector<int>& A) {\n int n = A.size(), res = 0;\n if (n <= 1)\n return n;\n if (n == 2)\n return 1;\n\n vector<int> uniqs;\n\n unordered_map<int, int> f;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n // lame sauce\n ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);\n\n int ans = 0;\n // count frequency of ints\n int m = 0;\n unordered_map<int, int> F;\n for (int &n: arr) {\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n unordered_map<int, int> freqMap;\n for (auto i: arr)\n freqMap[i]++;\n vector<int> freq;\n freq.reserve(freqMap.size());\n for (auto [_, f]: freqMap)\n f...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n std::unordered_map<int, int> counter;\n for (auto const& num: arr){\n counter[num]++;\n }\n\n std::vector<int> vcounter;\n vcounter.reserve(counter.size());\n for (auto const& pair: coun...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n unordered_map<int,int> counter;\n priority_queue<int, vector<int>, greater<int> > pq;\n for (int x : arr){\n counter[x]++;\n }\n int curr = 0;\n int ans = IN...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n= arr.size();\n map<int,int> m;\n int target = n/2;\n for(int i=0;i<n;i++){\n m[arr[i]]++;\n }\n arr.clear();\n for(auto i : m){\n arr.push_back(i.second);\n }\...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int, int> numToFreq;\n for (auto num : arr) {\n numToFreq[num]++;\n }\n vector<int> freqFreq(arr.size() + 1, 0); // frequency of frequency\n for (auto [num, freq] : numToFreq) {\n...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "#include <cmath>\nclass Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int, int> m;\n int n = arr.size();\n for(const int& i : arr){\n m[i]++;\n }\n vector<int> freqs(n+1, 0); // freqs[i] = number of elements repeated i times \n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int,int>mp;\n int n=arr.size(),k=(n+1)/2,answer=0,i=n;\n vector<int>list(n+1,0);\n\n for(auto num:arr)mp[num]++;\n for(auto it:mp)list[it.second]++;\n while(k>0){\n answer+...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n\t // Sort the element count from max to min\n\n\t // Construct a hash of element to count\n\t std::unordered_map<int, int> hash;\n\t for(int i = 0; i < arr.size(); i++) {\n\t\t hash[arr[i]] += 1;\n\t }\n\n\t // Convert...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
0
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size(),sum=0,count=0;\n unordered_map<int,int>mp;\n for(int i=0;i<n;i++){\n mp[arr[i]]++;\n\n }\n vector<int> freq;\n for (const auto& entry : mp) {\n freq.push_back(en...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int,int> mp;\n for(int i=0;i<arr.size();i++)\n mp[arr[i]]++;\n // priority_queue<pair<int,int>> pq;\n vector<int> v;\n for(auto it:mp)\n v.push_back(it.second);\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int, int> m;\n for(int a: arr){\n m[a]++;\n }\n priority_queue<int, vector<int>> pq;\n for(auto it: m){\n pq.push({it.second});\n }\n\n int target = arr.s...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "auto init = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 'c';\n}();\nclass Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int,int>mp;\n for(auto i : arr){\n mp[i]++;\n }\n int n = arr....
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n // count the number of occurrences of each element\n std::unordered_map<int, int> occurrences;\n\n for (int i : arr) {\n auto it = occurrences.find(i);\n\n if (it == occurrences.end()) {\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int, int> numFreqs;\n for (const int& num: arr) {\n numFreqs[num] += 1;\n }\n \n vector<int> freqs; // we use it because if insert the heap step by step is O(nlogn)\n for ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "\n\nclass Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n map<int,int>mp;\n priority_queue<int>maxHeap;\n int target = arr.size() / 2; \n int removed = 0;\n int setSize = 0;\n \n for(auto&num : arr){\n mp[num]++;\n }\n \n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n int k=n;\n int t=n/2;\n int p=0;\n vector<int>ans;\n map<int,int>mp;\n for(auto e:arr)\n {\n mp[e]++;\n } \n priority_queue<int> q;\n\t\t\tfor(auto i:mp) q.push(i.second...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "\n\nclass Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n map<int,int>mp;\n priority_queue<int> maxHeap;\n int target = arr.size() / 2; // We need to remove at least half of the elements\n int removed = 0;\n int setSize = 0;\n // Count the frequency o...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n map<int,int>mp;\n priority_queue<int>maxHeap;\n int target=arr.size()/2;\n int removed=0;\n int setSize=0;\n for(auto &num:arr)\n mp[num]++;\n for(auto &x:mp)\n {\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
1
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) \n {\n std::map<int, int> numCount;\n\n for(auto i:arr)\n {\n numCount[i]++;\n }\n\n std::priority_queue<int> maxHeap;\n\n for(auto i:numCount) \n {\n maxHeap.push(i.se...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n\n int ans = arr.size();\n int n = arr.size();\n map<int,int> mp;\n for(int i =0;i<arr.size();i++){\n mp[arr[i]]++;\n }\n\n vector<int> freq;\n for(auto it = mp.begin();it!=mp.end(...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n \n int size = arr.size();\n\n map<int,int> mpp;\n\n for( int i = 0 ; i < size ; i++ )\n {\n mpp[ arr[i] ]++;\n }\n\n priority_queue<int> pr;\n\n for( auto it : mpp )\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int minSetSize(const std::vector<int>& nums) con...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int minSetSize(const std::vector<int>& nums) con...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int minSetSize(const std::vector<int>& nums) con...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int minSetSize(const std::vector<int>& nums) con...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int,int> mp;\n for(auto x : arr){\n mp[x]++;\n }\n priority_queue<pair<int,int> > pq;\n for(auto x : mp){\n pq.push({x.second,x.first});\n }\n int n = ar...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n std::unordered_map<int, int> freq;\n for(auto& i: arr){\n freq[i]++;\n }\n\n std::priority_queue<pair<int,int>> q;\n for(auto& x: freq){\n q.push({x.second, x.first});\n }\n\n...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n unordered_map<int,int> map;\n for(auto it: arr)\n map[it]++;\n priority_queue<pair<int,int>> pq;\n for(auto it: map)\n {\n pq.push({it.second,it.first});\n...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int,int> mp;\n for(int i=0;i<arr.size();i++)\n mp[arr[i]]++;\n priority_queue<pair<int,int>> pq;\n for(auto it:mp)\n pq.push({it.second,it.first});\n int val=0,cnt=0;\n...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
2
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n =arr.size();\n unordered_map<int,int>mpp;\n for(int i=0;i<n;i++){\n mpp[arr[i]]++;\n }\n priority_queue<pair<int,int>>maxH;\n for(auto it:mpp){\n maxH.push({it.second,it...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int,int> mp;\n for(auto it:arr) mp[it]++;\n vector<int> val;\n int n=arr.size()/2;\n for(auto it:mp){\n val.push_back(it.second);\n }\n\n\n sort(val.rbegin(),val.ren...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n = arr.size();\n unordered_map<int, int> mp;\n for(auto num: arr) {\n mp[num]++;\n }\n vector<int> freq;\n for(auto& it:mp) {\n freq.push_back(it.second);\n }\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n std::unordered_map<int, int> nums_count;\n for (size_t i = 0; i < arr.size(); i++) {\n nums_count[arr[i]]++;\n }\n\n std::vector<int> counts;\n for (auto it = nums_count.begin(); it != nums_cou...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<int, int> hash; // value, count\n for (int v : arr) {\n hash[v]++;\n }\n /* now we need to sort by the count\n * and btw we don't need the values themselve */\n vector<int...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n struct Pair\n {\n int number;\n int frequency;\n };\n int minSetSize(vector<int>& arr) {\n int original_size = arr.size();\n map<int,int> frequency;\n for(int i:arr)\n {\n frequency[i]++;\n }\n vector...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n priority_queue<pair<int,int>>pq;\n map<int,int>mpp;\n for(auto it:arr) mpp[it]++;\n for(auto it:mpp){\n pq.push({it.second,it.first});\n } \n int count=0...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n map<int,int>mp;\n for(auto x:arr) mp[x]++;\n priority_queue<pair<int,int>>pq;\n for(auto x:mp){\n pq.push({x.second,x.first});\n }\n\n int ans=0,curSize=n;\n ...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<long,long>mpp;\n \n for(int i=0;i<arr.size();i++){\n mpp[arr[i]]++;\n }\n \n int count=1;\n vector<int> v;\n \n for(auto x:mpp){\n v.push_ba...
1,464
<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p> <p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p> <p>&nbsp;</p> <p><strong class="ex...
3
{ "code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n map<int,int>mp;\n for(int i=0;i<n;i++){\n mp[arr[i]]++;\n }\n vector<int>res;\n for(auto &x:mp){\n res.push_back(x.second);\n }\n sort(res.rb...