id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n\n int n = tasks.size();\n for (int i = 0; i < n; i++) {\n tasks[i] = {tasks[i][0], tasks[i][1], i};\n }\n sort(tasks.begin(), tasks.en...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "class Solution {\nprivate:\n int ansIdx = 0;\n void processTask(priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>& execTime, vector<int>& order, long long& currTime) {\n auto currTask = execTime.top();\n execTime.pop();\n order[ansIdx++] = currTask.s...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<pair<pair<int, int>, int>>temp;\n for (int i = 0; i < tasks.size(); i++) {\n temp.push_back({{tasks[i][0], tasks[i][1]}, i});\n }\n sort(temp.begin(), temp.end());\n vect...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<int>ans;\n vector<vector<int>>temp;\n for(int i =0;i<tasks.size();i++){\n temp.push_back({tasks[i][0],tasks[i][1],i});\n }\n priority_queue<pair<int,int>,vector<pair<int,...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "class Solution {\npublic:\nvector<int> getOrder(vector<vector<int>>& tasks) {\n int n = tasks.size();\n \n // Add the original index to each task.\n vector<vector<int>> indexedTasks;\n for (int i = 0; i < n; ++i) {\n indexedTasks.push_back({tasks[i][0], tasks[i][1], i});\n }\n \...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "#define p pair<int,int>\nclass Solution {\npublic:\n\n struct lamda{\n bool operator()(p &p1,p &p2){\n if(p1.first==p2.first) return p1.second>p2.second;\n return p1.first>p2.first;\n }\n };\n\n\n vector<int> getOrder(vector<vector<int>> tasks) {\n for(in...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
2
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n\n int rowSize = tasks.size();\n int colSize = 3;\n\n vector<vector<int>> arr(rowSize, vector<int>(3, 0)); // startingTime, processingTime, idx\n\n for(int i = 0; i < tasks.size(); i++){\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n int n = tasks.size();\n vector<int> ans ;\n\n for(int i=0 ; i<n ; i++){\n tasks[i].push_back(i);\n }\n\n sort(tasks.begin() , tasks.end());\n priority_queue<vector<int> ,...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n struct cmp {\n bool operator()(vector<int>& l, vector<int>& r) {\n if (l[1] == r[1]) \n return l[2] > r[2]; // Larger index has lower priority\n return l[1] > r[1]; // Larger processing time has lower priority\n }\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n for(int i=0; i<tasks.size(); ++i){\n tasks[i].push_back(i);\n }\n\n sort(tasks.begin(), tasks.end());\n\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "static auto init_io = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n int n = tasks.size();\n for(int i = 0; i < n; i++)\n {\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n \n // monotonic queue queued<enqueueTime, processingTime, index>\n // min pq free <processing time, index>\n\n vector<vector<int>> sortedTasks;\n for (int i = 0; i < tasks.size(); i++)\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "#include <vector>\n#include <queue>\n#include <algorithm>\n\nusing namespace std;\n\nclass cmp1 {\npublic:\n // Custom comparator for the priority queue (min-heap)\n bool operator()(const pair<long long, int>& a, const pair<long long, int>& b) {\n // Sort by processing time first, if equal, th...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<vector<long>> tasksMap;\n for (int i = 0; i < tasks.size(); ++i) {\n tasksMap.push_back({tasks[i][0], tasks[i][1], i});\n }\n priority_queue<pair<int, int>, vector<pair<int, int...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\n\n int n = tasks.size();\n map<int, vector<pair<int, int>>> m;\n\n for (int i = 0; i < n; i++) {\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<pair<vector<int>, int>> taskI;\n for(int i = 0; i < tasks.size(); i++)\n taskI.push_back({tasks[i],i});\n sort(taskI.begin(), taskI.end());\n vector<int> ans;\n long long...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Compare {\npublic:\n bool operator()(vector<int>& a, vector<int>& b) {\n if(a[1] == b[1])\n return a[2] > b[2];\n return a[1] > b[1];\n }\n};\n\nbool vectorComparator(vector<int>& a, vector<int>& b) {\n return a[0] < b[0];\n}\n\nclass Solution {\npublic:\n vector<...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) \n {\n vector<pair<vector<int>, int >> tasksI;\n\n for (unsigned i = 0; i < tasks.size(); ++i)\n {\n tasksI.push_back({ tasks.at(i), i });\n }\n\n std::sort(tasksI.begin(), tasks...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n priority_queue<pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>>>pq;\n vector<pair<vector<int> , int >>v; \n vector<int>ans; \n for(int i = 0;i<tasks.size();i++)\n {\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<pair<int, pair<int, int> > > tasksOrdered;\n vector<int> ans;\n\t\tint index=0;\n\t\tfor(auto task: tasks) {\n tasksOrdered.push_back({task[0],{task[1],index++}});\n }\n sort(ta...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n priority_queue<pair<pair<int , int> , int> , vector<pair<pair<int , int> , int>> , greater<pair<pair<int , int> , int>>>pq;\n vector<pair<vector<int> , int >>v; \n vector<int>ans; \n for(int i = ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) \n {\n priority_queue<pair<pair<int , int> , int> , vector<pair<pair<int , int> , int>> , greater<pair<pair<int , int> , int>>>pq;\n \n vector<pair<vector<int> , int >>v; \n vector<int>ans;\n\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>> tasks) {\n int n = tasks.size();\n for (int i = 0; i < n; i++) tasks[i].push_back(i);\n tasks.push_back({(int) 2e9, (int) 2e9, (int) 2e9});\n std::priority_queue<pair<int, int>, vector<pair<int, int>>, std::...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>> tasks) {\n int n = tasks.size();\n for (int i = 0; i < n; i++) tasks[i].push_back(i);\n tasks.push_back({(int) 2e9, (int) 2e9, (int) 2e9});\n std::priority_queue<pair<int, int>, vector<pair<int, int>>, std::...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n static bool cmp(const vector<int>&arr,const vector<int>&brr)\n {\n if(arr[0]==brr[0])\n {\n return arr[1]<brr[1];\n }\n return arr[0]<brr[0];\n }\n\n vector<int> getOrder(vector<vector<int>>& tasks) \n {\n vector<int>r...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n\n/**\n[2, 15], [12, 24], [16, 9], [18, 18], [19, 13], [21, 10], []\n[2, 15] - 17 - 6\n[12, 24], [16, 9]\n[16, 9] - 25 - 1\n[12, 24], [19, 13], [21, 10], [18, 18]\n[21, 10] - 31 - 2\n[12, 24], [19, 13], [18, 18]\n**/\n vector<int> getOrder(vector<vector<int>>& tasks) {\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "#define ppi pair<pair<int,int>,int>\n#define pi pair<int,int>\n\n\nclass Compare\n{\npublic:\n bool operator()(ppi&p1,ppi&p2)\n {\n if(p1.first.second==p2.first.second)\n {\n return p1.second > p2.second;\n }\n return p1.first.second>p2.first.second;\n }\n\n};\n\ncl...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n const int n = tasks.size();\n vector<vector<int>> copyTask; \n \n for(int i = 0; i < n; ++i) {\n int start = tasks[i][0];\n int duration = tasks[i][1];\n \...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n const int n = tasks.size();\n vector<vector<int>> copyTask; \n \n for(int i = 0; i < n; ++i) {\n int start = tasks[i][0];\n int duration = tasks[i][1];\n \...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n const int n = tasks.size();\n vector<vector<int>> copyTask; \n \n for(int i = 0; i < n; ++i) {\n int start = tasks[i][0];\n int duration = tasks[i][1];\n \...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n const int n = tasks.size();\n vector<vector<int>> copyTask; \n \n for(int i = 0; i < n; ++i) {\n int start = tasks[i][0];\n int duration = tasks[i][1];\n \...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>> tasks)\n {\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> priority_tasks;\n \n vector<vector<int>> all_tasks;\n\n for(int idx = 0; idx < tasks.size(); idx++)\n {\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<vector<int>> original;// start Time, Process Time, index\n priority_queue<vector<long long>, vector<vector<long long>>, greater<vector<long long>> > PQ; // Process Time, index. \n //sort(tasks.be...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n//enquetime,\n \n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<vector<int>> v;\n for(int i=0;i<tasks.size();i++)\n {\n v.push_back({tasks[i][0],tasks[i][1],i});\n }\n sort(v.begin(),v.end());\n priority_queue<...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<vector<int>> sortedTasks;\n int n = tasks.size();\n for(int i=0;i<tasks.size();i++){\n sortedTasks.push_back({tasks[i][0], tasks[i][1], i});\n }\n sort(sortedTasks.begin(...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n static bool compare(const vector<int>& a, const vector<int>& b) {\n if (a[1] == b[1]) {\n return a[2] > b[2];\n }\n return a[1] > b[1];\n }\n vector<int> getOrder(vector<vector<int>>& tasks) {\n priority_queue<vector<int>, vector<v...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<vector<int>> original;// start Time, Process Time, index\n priority_queue<vector<long long>, vector<vector<long long>>, greater<vector<long long>> > PQ; // Process Time, index. \n //sort(tasks.be...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n int n = tasks.size();\n vector<vector<int>> t(n, vector<int>(3));\n for (int i = 0; i < n; i++) {\n t[i][0] = tasks[i][0];\n t[i][1] = tasks[i][1];\n t[i][2] = i;\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n std::vector<int> getOrder(std::vector<std::vector<int>>& tasks) {\n int n = tasks.size(); //declares an integer n and initializes it with the number of tasks\n std::vector<std::vector<int>> indexedTasks(n);\n\n for (int i = 0; i < n; ++i) {\n i...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n \n // monotonic queue queued<enqueueTime, processingTime, index>\n // min pq free <processing time, index>\n\n vector<vector<int>> list;\n for (int i = 0; i < tasks.size(); i++)\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "\n\nclass Solution {\npublic:\n // Comparator for the priority queue (min-heap by the first element)\n \n\n vector<int> getOrder(vector<vector<int>>& tasks) {\n int n = tasks.size();\n vector<vector<int>> newy; \n priority_queue<pair<int, int>, vector<pair<int, int>>, greater...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "\nclass Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n vector<vector<int>>t;\n int i=0;\n for(auto task:tasks){\n \n task.push_back(i);\n t.push_back(task);\n i++;\n }\n sort(begin(t),end(t));\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n int n=tasks.size();\n vector<vector<int>>taskCp;\n for(int i=0;i<n;i++){\n auto v=tasks[i];\n v.push_back(i);\n taskCp.push_back(v);\n }\n sort(taskCp.begi...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "struct cmp {\n constexpr bool operator()( vector<int> const& a, vector<int> const& b) const noexcept {\n return a[0] < b[0] || a[0] == b[0] && a[2] > b[2];\n }\n};\n\nclass Solution {\n\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n ios::sync_with_stdio(false);\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n \n // monotonic queue queued<enqueueTime, processingTime, index>\n // min pq free <processing time, index>\n\n vector<vector<int>> list;\n for (int i = 0; i < tasks.size(); i++)\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n \n // monotonic queue queued<enqueueTime, processingTime, index>\n // min pq free <processing time, index>\n\n vector<vector<int>> list;\n for (int i = 0; i < tasks.size(); i++)\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n \n // monotonic queue queued<enqueueTime, processingTime, index>\n // min pq free <processing time, index>\n\n vector<vector<int>> list;\n for (int i = 0; i < tasks.size(); i++)\n ...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& tasks) {\n set<pair<int, int> > processingTimeAndIndexSet;\n set<pair<int, int> >::iterator it;\n vector<vector<int>> tasksWithIndex;\n for(int i=0;i<tasks.size();i++) {\n tasksWithIndex.push_bac...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n static bool sortvec(vector<int>&a, vector<int>&b){\n if(a[0]!=b[0])\n return a[0]<b[0];\n else if(a[1]!=b[1])\n return a[1]<b[1];\n else\n return a[2]<b[2];\n }\n vector<int> getOrder(vector<vector<int>>& tasks) {\n for(i...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n static bool sortvec(vector<int>&a, vector<int>&b){\n if(a[0]!=b[0])\n return a[0]<b[0];\n else if(a[1]!=b[1])\n return a[1]<b[1];\n else\n return a[2]<b[2];\n }\n vector<int> getOrder(vector<vector<int>>& tasks) {\n for(i...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& mat) {\n\n int n = mat.size();\n vector<int> ans;\n\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n\n vector<vector<int>> g;\n\n for(int i=0;i<n;i++) {\n g.p...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "class Solution {\npublic:\n vector<int> getOrder(vector<vector<int>>& arr) {\n int n = arr.size(), ct = 0;\n for(auto &i : arr){\n i.push_back(ct);\n ct++;\n }\n vector<int>result;\n priority_queue<vector<int>,vector<vector<int>>,greater<vector<in...
1,962
<p>You are given <code>n</code>​​​​​​ tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>​​​​​​th</sup></code>​​​​ task will be available to process a...
3
{ "code": "#include <vector>\n#include <queue>\n#include <algorithm>\n\nclass Solution {\npublic:\n std::vector<int> getOrder(std::vector<std::vector<int>>& tasks) {\n // {startTime, processTime, index}\n std::vector<std::vector<int>> tasks_vec;\n for (int i = 0; i < tasks.size(); i++) \n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\n public:\n int maxFrequency(vector<int>& nums, int k) {\n int ans = 0;\n long sum = 0;\n\n ranges::sort(nums);\n\n for (int l = 0, r = 0; r < nums.size(); ++r) {\n sum += nums[r];\n while (sum + k < static_cast<long>(nums[r]) * (r - l + 1))\n sum -= nums[l++]...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\n public:\n int maxFrequency(vector<int>& nums, int k) {\n int ans = 0;\n long sum = 0;\n\n ranges::sort(nums);\n\n for (int l = 0, r = 0; r < nums.size(); ++r) {\n sum += nums[r];\n while (sum + k < static_cast<long>(nums[r]) * (r - l + 1))\n sum -= nums[l++]...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\n public:\n int maxFrequency(vector<int>& nums, int k) {\n int ans = 0;\n long sum = 0;\n\n ranges::sort(nums);\n\n for (int l = 0, r = 0; r < nums.size(); ++r) {\n sum += nums[r];\n while (sum + k < static_cast<long>(nums[r]) * (r - l + 1))\n sum -= nums[l++]...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\n public:\n int maxFrequency(vector<int>& nums, int k) {\n int ans = 0;\n long sum = 0;\n\n ranges::sort(nums);\n\n for (int l = 0, r = 0; r < nums.size(); ++r) {\n sum += nums[r];\n while (sum + k < static_cast<long>(nums[r]) * (r - l + 1))\n sum -= nums[l++]...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int ans = 0;\n long sum = 0;\n\n ranges::sort(nums);\n\n for (int l = 0, r = 0; r < nums.size(); ++r) {\n sum += nums[r];\n while (sum + k < static_cast<long>(nums[r]) * (r - l + 1))\n sum -= nums...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\n void merge(vector<int> &nums,int low,int mid,int high){\n int i=low,j=mid+1;\n // cout<<high<<low;\n int temp[high-low+1];\n int k=0;\n while(i<=mid && j<=high){\n if(nums[i]<nums[j])temp[k++]=nums[i++];\n else temp[k++]=nums[j+...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int prefix[100000+1] = {0};\n for(auto x: nums){\n prefix[x]++;\n }\n int count=0;\n int maxi = 0;\n int operations = 0;\n int left =0;\n int leftcount=0;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "//https://hyper-meta.blogspot.com/\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();\nint fre[100001];\nclass Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n const int sz=nums.size();\n if(...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "//https://hyper-meta.blogspot.com/\n#pragma GCC target(\"avx,mmx,sse2,sse3,sse4\")\nauto _=[]()noexcept{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();\nint fre[100001];\nclass Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n const int sz=nums.size();\n if(...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& v, long long k) {\n sort(v.begin(), v.end());\n long long total = 0;\n long long left = 0;int ans = 0;\n\n for (long long right = 0; right < v.size(); right++) {\n total += v[right];\n\n //we shou...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n bool possible(vector<int>& nums,int mid, int k)\n { \n long long int windowsum=0,totalsum=0;\n for(int i=0;i<mid;++i)\n windowsum+=nums[i];\n \n totalsum=1LL*nums[mid-1]*mid;\n \n if(totalsum-windowsum<=k)\n return 1;\n \n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n \n sort(nums.begin(), nums.end());\n\n int currAns = 1, maxAns = 1, prev = 0;\n long long op = 0;\n for(int i=1; i<nums.size(); ++i) {\n \n int diff = nums[i] - nums[i-1];\...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>&v,int k) {\n sort(v.begin(), v.end());\n int n = v.size();\n long long currSum = 0;\n long long currTargetSum = 0;\n long long temp = 0;\n int ans = 0;\n for(int l = 0, r = 0; r < n; r++) {\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n int currLeft = 0;\n long double currSum = 0;\n int maxFreq = 1;\n\n for (int currRight = 0; currRight < nums.size(); currRight++) {\n currSum += nums...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n long long total = 0;\n int max_freq = 1;\n int i = 0; // Left pointer for the sliding window\n // Step 2: Use sliding window approach\n for (int j = 1; j...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
0
{ "code": "class Solution {\npublic:\n int maxFrequency(std::vector<int>& nums, int k) {\n std::sort(nums.begin(), nums.end());\n \n // Initialize the sliding window pointers and the total increment cost\n int left = 0;\n int64_t totalIncrement = 0; // Use int64_t for handling ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
2
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n // sort(nums.begin(), nums.end());\n // int max_freq = 1;\n // for (int i = 0; i < nums.size(); i++) {\n // int temp = k, freq = 1;\n // for (int j = i + 1; j < nums.size() && temp >= 0;...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
2
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n int left = 0, right = 0;\n long res = 0, total = 0;\n\n while (right < nums.size()) {\n total += nums[right];\n\n while (nums[right] * static_cas...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n \n long long total = 0;\n int left = 0, result = 1;\n \n // Sliding window approach\n for (int right = 0; right < nums.size(); ++right) {\n total += nums[right];\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int count[100001]={0};\n \n for(int i=0;i<nums.size();i++)\n {\n count[nums[i]]++;\n }\n \n sort(nums.begin(),nums.end());\n \n int i=count[nums[0]];\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int count[100001]={0};\n \n for(int i=0;i<nums.size();i++)\n {\n count[nums[i]]++;\n }\n \n sort(nums.begin(),nums.end());\n \n int i=count[nums[0]];\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int count[100001]={0};\n \n for(int i=0;i<nums.size();i++)\n {\n count[nums[i]]++;\n }\n \n sort(nums.begin(),nums.end());\n int i=0;\n while(i<nums.size()...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int count[100001]={0};\n \n for(int i=0;i<nums.size();i++)\n {\n count[nums[i]]++;\n }\n \n sort(nums.begin(),nums.end());\n \n int i=count[nums[0]];\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& v, int k) {\n sort(v.begin(), v.end());\n int n = v.size();\n long long int prefix[n + 1];\n memset(prefix, 0, sizeof(prefix));\n prefix[0] = v[0];\n for (int i = 1; i < n; i++) {\n prefix[i] =...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n long long s[n + 1];\n s[0] = 0;\n for (int i = 1; i <= n; ++i) {\n s[i] = s[i - 1] + nums[i - 1];\n }\n int l = ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n long long s[n + 1];\n s[0] = 0;\n for (int i = 1; i <= n; ++i) {\n s[i] = s[i - 1] + nums[i - 1];\n }\n int l = ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n long long s[n + 1];\n s[0] = 0;\n for (int i = 1; i <= n; ++i) {\n s[i] = s[i - 1] + nums[i - 1];\n }\n int l = ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n long long s[n + 1];\n s[0] = 0;\n for (int i = 1; i <= n; ++i) {\n s[i] = s[i - 1] + nums[i - 1];\n }\n int l = ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int minNum = *min_element(nums.begin(), nums.end());\n int maxNum = *max_element(nums.begin(), nums.end());\n int range = maxNum - minNum + 1;\n vector<int> frequency(range, 0);\n \n for ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "//50-ms\nclass Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int minNum = *min_element(nums.begin(), nums.end());\n int maxNum = *max_element(nums.begin(), nums.end());\n int range = maxNum - minNum + 1;\n vector<int> frequency(range, 0);\n \n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "//50-ms\nclass Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int minNum = *min_element(nums.begin(), nums.end());\n int maxNum = *max_element(nums.begin(), nums.end());\n int range = maxNum - minNum + 1;\n vector<int> frequency(range, 0);\n \n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int minNum = *min_element(nums.begin(), nums.end());\n int maxNum = *max_element(nums.begin(), nums.end());\n int range = maxNum - minNum + 1;\n vector<int> frequency(range, 0);\n \n for ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int minNum = *min_element(nums.begin(), nums.end());\n int maxNum = *max_element(nums.begin(), nums.end());\n int range = maxNum - minNum + 1;\n vector<int> frequency(range, 0);\n \n for ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int minNum = *min_element(nums.begin(), nums.end());\n int maxNum = *max_element(nums.begin(), nums.end());\n int range = maxNum - minNum + 1;\n vector<int> frequency(range, 0);\n \n for ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.rbegin(), nums.rend());\n int l = 0, r = 0;\n int t = 0;\n int ans = 0;\n while(r<nums.size()){\n \n int x = nums[l] - nums[r];\n t += x;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\n #define ll long long\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n ios::sync_with_stdio(false);\n cin.tie(0);\n\n sort(nums.rbegin() , nums.rend());\n\n ll cnt = 1;\n ll val = k;\n int n = nums.size();\n ll ans = 1, start...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.rbegin(), nums.rend());\n int l = 0, r = 0;\n int t = 0;\n int ans = 0;\n while(r<nums.size()){\n \n int x = nums[l] - nums[r];\n t += x;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\n #define ll long long\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.rbegin() , nums.rend());\n\n ll cnt = 1;\n ll val = k;\n int n = nums.size();\n ll ans = 1, start = 0, end = 1;\n\n while(end < n) {\n if( v...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n queue<pair<int, int>> queue;\n int queuecount = 0;\n long kused = 0;\n int ans = 0;\n int n = nums.size();\n for (int x = 0;;) {\n int ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n sort(nums.begin(), nums.end());\n vector<int> d(nums.size(), 0);\n for (int i=nums.size()-1; i>0; i--)\n {\n d[i]=nums[i]-nums[i-1];\n }\n long l=0, r=0, temp=0, ans=1;\n ...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n int n=nums.size();\n if(n==1) {\n return 1;\n }\n vector<int> num=nums;\n sort(num.begin(),num.end());\n long long sum=num[0];\n int mx=1;\n int left=0,right=1;\n...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n deque<int> dq;\n sort(nums.begin(), nums.end());\n dq.push_back(nums[0]);\n int answer = 1;\n long long operations = 0;\n for (int i = 1; i < nums.size(); i++)\n {\n int...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n\n queue<int>bfsQueue;\n sort(nums.begin(), nums.end());\n int maxFreq = 1;\n bfsQueue.push(nums[nums.size()-1]);\n int i = nums.size()-2;\n while(i >= 0) {\n if(bfsQueue.front(...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n deque<int> dq;\n sort(nums.begin(), nums.end());\n dq.push_back(nums[0]);\n int answer = 1;\n long long operations = 0;\n for (int i = 1; i < nums.size(); i++)\n {\n //a...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(vector<int>& nums, int k) {\n queue<int> dq;\n sort(nums.begin(), nums.end());\n dq.push(nums[0]);\n int previous = nums[0];\n int answer = 1;\n long long operations = 0;\n for (int i = 1; i < nums.size(); i++)...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "class Solution {\npublic:\n int maxFrequency(std::vector<int>& nums, int k) {\n countingSort(nums); // Sort the array using counting sort\n int start = 0; // Start index of the current subarray\n long long subarraySum = 0; // Sum of elements in the current subarray\n int maxF...
1,966
<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p> <p>Return <...
3
{ "code": "// Idea: Greedy, Prefix Sum, Binary Search, Sorting\nclass Solution {\npublic:\n // _BinarySearch\n int maxFrequency(vector<int>& nums, int k) {\n std::ranges::sort(nums);\n const auto& a = nums;\n const int n = a.size();\n // create the prefix sum array, for quick range-s...