id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n const int N = nums.size();\n\n multiset<int> window(nums.begin(), nums.begin() + k);\n auto mid = next(window.begin(), k / 2);\n\n vector<double> ans(N - k + 1);\n int i = 0;\n... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\n public:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> ans;\n multiset<double> window(nums.begin(), nums.begin() + k);\n auto it = next(window.begin(), (k - 1) / 2);\n\n for (int i = k;; ++i) {\n const double median = k % 2 == 0 ? (*it... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n# define ll long long\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n priority_queue<pair<ll,ll>>mx;\n int n=nums.size();\n priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>mn;\n int ctmx=0,ctmn=0;\n vect... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n multiset<int> window(nums.begin(), nums.begin() + k);\n auto mid = next(window.begin(), k / 2);\n vector<double> result;\n \n for (int i = k; ; i++) {\n // Для четны... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n const int n = nums.size();\n vector<double> ans;\n multiset<double> set(nums.begin(), nums.begin() + k);\n auto it = next(set.begin(), (k - 1) / 2);\n\n for (int i = k; i <= n;... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\n public:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> ans;\n multiset<double> window(nums.begin(), nums.begin() + k);\n auto it = next(window.begin(), (k - 1) / 2);\n\n for (int i = k;; ++i) {\n const double median = k % 2 == 0 ? (*it... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "#include <algorithm>\n#include <deque>\n#include <iostream>\n#include <optional>\n#include <queue>\n#include <tuple>\n#include <vector>\n#include <unordered_map>\n\n// min-heap\nusing HeapType = std::priority_queue<long, std::vector<long>, std::greater<long>>;\n\nclass Solution {\npublic:\n double get_m... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int64_t k) {\n std::vector<double> medians;\n std::unordered_map<int64_t, int64_t> hash_table;\n priority_queue<int64_t> lo;\n priority_queue<int64_t, vector<int64_t>, greater<int64_t>> hi;\n\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "struct Queue\n{\n multiset<int> max;\n multiset<int> min;\n\n int topMax()\n {\n return *max.rbegin();\n }\n\n int topMin()\n {\n return *min.begin();\n }\n\n void push(int val)\n {\n if(max.size() == min.size())\n {\n max.emplace(val);\n... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\n \n unordered_map<int,int>mp1;\n unordered_map<int,int>mp2;\n \n priority_queue<int>pq1;\n priority_queue<int,vector<int>,greater<int>>pq2;\n \n int s1,s2;\n \n void filterPQ(){\n while( !pq1.empty() && mp1[pq1.top()] > 0){\n mp1[pq1.top()]-... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n std::priority_queue<int> low;\n std::priority_queue<int, vector<int>, std::greater<int>> high;\n\n std::unordered_map<int, int> todeletelow;\n std::unordered_map<int, int> todeletehig... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 1 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n double median(const vector<int>& sorted) {\n long median = sorted[sorted.size() / 2];\n if (sorted.size() % 2 == 0) {\n return (median + sorted[sorted.size() / 2 - 1]) / 2.0;\n }\n\n return median;\n }\n\n void medianSlidingWindow(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<int> segtree;\n map<int,int> mp;\n\n int n;\n void update(int pos,int l,int r, int idx,int sum)\n {\n if(pos<l|| pos>r)\n return;\n if(l==r)\n {\n segtree[idx]+=sum;\n return;\n }\n int mid... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& v, int k) {\n int n=v.size();\n vector<double>medians(n-k+1);\n multiset<int>low,high;\n vector<int>first(k);\n for(int i=0;i<k;i++){\n first[i]=v[i];\n }\n sort(first.... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n // 2 multiset - lower and upper\n vector<double> medians(nums.size()-k+1);\n if (k==1) {\n for (int i=0; i<nums.size(); i++) medians[i] = nums[i];\n return medians;\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n // similar to median problem\n // stores lower (k+1)/2 values\n int n = nums.size();\n multiset<int> lower;\n // stores k/2 values\n multiset<int> upper;\n\n for(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n // similar to median problem\n // stores lower (k+1)/2 values\n int n = nums.size();\n multiset<int> lower;\n // stores k/2 values\n multiset<int> upper;\n\n for(... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n // build the 2 set\n vector<int> first_k(nums.begin(), nums.begin() + k-1);\n sort(first_k.begin(), first_k.end());\n multiset<int> lower, higher;\n for (int i = 0; i < k / 2; ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n multiset<int> left, right;\n vector<int> win;\n for (int i = 0; i<k; i++){\n win.push_back(nums[i]);\n }\n // cout << win[0] << win[1] << win[2] << \"\\n\";\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> result;\n if(k == 1) {\n for(int i : nums) result.push_back(i);\n return result;\n }\n int n = nums.size();\n int lsz = k/2, rsz = k-k/2;\n... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n if (k == 1)\n {\n vector<double> res;\n for (auto it : nums)\n {\n res.push_back(it * 1.0);\n }\n\n return res;\n }\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> res;\n res.reserve(nums.size());\n multiset<int> leftPart, rightPart;\n int leftSize = (k+1) / 2;\n int rightSize = k - leftSize;\n for (size_t i = 0; i <... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "//5:48\n/*\n1,3,-1,-3,5,3,6,7\n\n1,3,-1,-3\n\n-3,-1,1,3\n\n3,1\n\n-1,-3\n\ngreater k/2 min and smaller k/2 max ka average is our answer\n\ntake first k elements\nsort them,\nput first k/2 in a max heap\nand last k/2 in a min heap\n\n3,-1,-3,5\n-3,-1,3,5\n\n\n\n1,3,-1,-3,5,3,6,7\n1,3,-1,-3\n\n-3,-1,1,3\n\np... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n set<pair<int, int>> maxh; // get max element using *(maxh.rbegin());\n set<pair<int, int>> minh; // get min element using *(minh.begin());\n \n for(int i = 0; i < k; i++) {\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\nprivate:\n\n multiset<long long,greater<long long>> win_l;\n multiset<long long> win_r;\n\n void balanceSets() {\n while (win_l.size() > win_r.size() + 1){\n win_r.insert(*win_l.begin());\n win_l.erase(win_l.begin());\n }\n\n while (win_... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "#define pb push_back\n#define ll long long\nclass Solution {\n struct comp{\n bool operator()(const ll &l,const ll &r) const{\n return l > r;\n }\n };\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n multiset<ll>st; // right\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n \n if ((k&1) == 1)\n {\n vector<double> ans(nums.size()+1-k);\n multiset<int> lower, upper;\n for (int i = 0 ; i < k - 1 ; i++)\n {\n u... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\nprivate:\n double GetMedian(multiset<int, greater<int> >& left, multiset<int>& right, int k) {\n if(k%2) {\n return double(*left.begin());\n }\n return (*left.begin())/2.0 + (*right.begin())/2.0;\n }\n void Balance(multiset<int, greater<int> >& lef... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n \n\n\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n multiset<int> minS;\n multiset<int> maxS;\n\n for (int i = 0; i < k; i++)\n add(maxS, minS, nums[i]);\n\n vector<double> sol;\n sol.push_back(getMedian(max... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "\n\nclass Solution {\npublic:\nmultiset<int>left,right;\nint siz;\nvoid ins(int x){\n siz++;\n if(left.empty()&&right.empty()){\n right.insert(x);\n return;\n }\n if(x>(*right.begin())){\n right.insert(x);\n if(right.size()>left.size()+siz%2){\n left.inser... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n set<pair<int, int>> maxh, minh;\n \n // Initialize maxh with the first k elements\n for (int i = 0; i < k; i++) {\n maxh.insert({nums[i], i});\n }\n \n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\n private:\n multiset<double>MinH, MaxH;\n vector<double> ans;\n \n public: \n void balance()\n {\n if(MaxH.size() > MinH.size() + 1)\n {\n MinH.insert(*MaxH.rbegin());\n MaxH.erase(MaxH.find(*MaxH.rbegin()));\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n class Two_Sets {\n public:\n multiset<int> max_set;\n multiset<int> min_set;\n int size;\n Two_Sets (){\n size = 0;\n }\n void addNum(int num){\n if ( max_set.empty() ) max_set.insert(num);\n else{\... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class TwoSet {\n multiset<int> low, high;\n bool is_odd;\n\npublic:\n TwoSet(){\n is_odd=false;\n }\n\n void remove(int& x){\n if (x<=*low.rbegin()) {\n low.erase(low.find(x));\n if (!is_odd) {\n low.insert(*high.begin());\n h... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n class Two_Sets {\n public:\n multiset<int> max_set;\n multiset<int> min_set;\n int size;\n Two_Sets (){\n size = 0;\n }\n void addNum(int num){\n if ( max_set.empty() ) max_set.insert(num);\n else{\... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n int n=nums.size();\n int i=0;\n priority_queue<pair<double,int>>q1,q2;\n int count1=0,count2=0;\n vector<double>ans;\n unordered_set<int>us1,us2;\n // if(k%2==0){... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n int n=nums.size();\n int i=0;\n priority_queue<pair<double,int>>q1,q2;\n int count1=0,count2=0;\n vector<double>ans;\n unordered_set<int>us1,us2;\n // if(k%2==0){... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> ans;\n multiset<int, greater<int>> main;\n multiset<int> second;\n int i = 0, j = 0;\n while (j < nums.size()) {\n second.insert(nums.at(j));\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n multiset<int,greater<int>>l; multiset<int>r;\n int n=nums.size();\n vector<int>temp;\n for(int i=0;i<k;i++)\n temp.push_back(nums[i]);\n sort(temp.begin(),temp.end());... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n \n void ins(int i , multiset<long long int> &low , multiset<long long int> &high , vector<double> &v1) { \n if ( low.empty() ) { low.insert(i) ; }\n else { \n if ( i <= *(low.rbegin()) ) { \n if ( low.size() == high.size()) { low.ins... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n \n void ins(int i , multiset<long long int> &low , multiset<long long int> &high , vector<double> &v1) { \n if ( low.empty() ) { low.insert(i) ; }\n else { \n if ( i <= *(low.rbegin()) ) { \n if ( low.size() == high.size()) { low.ins... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\n struct value_info {\n long long value{};\n int idx{};\n };\n\n struct value_info_less {\n bool operator()(value_info l, value_info r) {\n return l.value < r.value;\n }\n };\n\n struct value_info_greater {\n bool operator()(valu... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\n multiset<int> min_heap;\n multiset<int> max_heap;\n void balance() {\n while (min_heap.size() > max_heap.size()) {\n int val = *min_heap.rbegin();\n auto it = min_heap.rbegin();\n it++;\n min_heap.erase(it.base());\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\nset<pair<double,int>> minheap;\n\tset<pair<double,int>,greater<pair<double,int>>> maxheap;\n //int i=0;\n void addNum(double num,int i) {\n if(maxheap.empty()||maxheap.begin()->first>num)maxheap.insert({num,i});\n else minheap.insert({num,i});\n\n if(mi... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class MyStructure{\n multiset<int,greater<int>> ms1;\n multiset<int> ms2;\n int window;\n\n public:\n MyStructure(int k){\n window=k;\n }\n\n double getMedian(){\n // cout<<\"gm\";\n double el1=*(ms1.begin());\n double el2=*(ms2.b... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\ntemplate<typename T>\nstruct comp {\n bool operator()(const T& lhs, const T& rhs) const {\n return lhs <= rhs; \n }\n};\n// ordered set... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\ntemplate<typename T>\nstruct comp {\n bool operator()(const T& lhs, const T& rhs) const {\n return lhs <= rhs; \n }\n};\n// ordered set... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\n multiset<int> left;\n multiset<int> right;\n double getmed(int k){\n if(k%2==0){\n // cout<<\",\"<<left.size()<<\" \"<<right.size()<<endl;\n return ( (double) (*(left.rbegin()) ) + (double) (*(right.begin()) ) ) / 2.0;\n }\n else{\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\n multiset<int> left;\n multiset<int> right;\n double getmed(int k){\n if(k%2==0){\n cout<<\",\"<<left.size()<<\" \"<<right.size()<<endl;\n return ( (double) (*(left.rbegin()) ) + (double) (*(right.begin()) ) ) / 2.0;\n }\n else{\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& vec, int k) {\n multiset<double> big, low;\n vector<double> ans;\n\n for (int i=0; i<k; ++i) big.insert(vec[i]);\n for (int i=0; i<k - (k/2+1); ++i) {\n low.insert(*big.begin());\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n\ntemplate <typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;\n\nclass Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "#include<bits/stdc++.h>\n\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntypedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key\n\n\nclass Solut... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 2 | {
"code": "#include<bits/stdc++.h>\n\n#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntypedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key\n\nclass Solutio... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n multiset<double> minH;\n multiset<double, greater<double>> maxH;\n \n void balanceHeaps()\n {\n if(maxH.size() > minH.size())\n {\n minH.insert(*maxH.begin()); \n maxH.erase(maxH.begin());\n }\n }\n \n double ge... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n multiset<int> firstHalf,secondHalf;\n vector<double> ans;\n for(int i=0;i<nums.size();i++){\n if(i>=k){\n if(secondHalf.find(nums[i-k])!=secondHalf.end()){\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "//VERY GOOD QUESTION\n//Intution is First put the elemet in minHEap\n//Then remove it and put the top element to maxHeap\n//If size of maxHeap is more than minHEap\n//Remove the top element of maxHeap and put it into minHeap\n//REmove the expired index\n//In minheap we put the higher value elemts.In maxHea... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n std::vector<double> medianSlidingWindow(std::vector<int>& nums, int k) {\n std::multiset<int> min;\n std::multiset<int, std::greater<int>> max;\n \n auto addNum = [&min, &max](int num) {\n if (min.empty()) {\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n template <typename T>\n class Median{\n queue<T> q;\n multiset<T> s1, s2;\n\n public:\n\n int size(){\n return q.size();\n }\n\n void push_back(T x){\n q.push(x);\n s2.insert(x);\n rebala... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n std::vector<double> medianSlidingWindow(std::vector<int>& nums, int k) {\n std::multiset<int> min;\n std::multiset<int, std::greater<int>> max;\n \n auto addNum = [&min, &max](int num) {\n if (min.empty()) {\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n std::vector<double> medianSlidingWindow(std::vector<int>& nums, int k) {\n std::multiset<int> min;\n std::multiset<int, std::greater<int>> max;\n \n auto addNum = [&min, &max](int num) {\n if (min.empty()) {\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n multiset<int> s1, s2;\n for (int i = 0; i < k; i++) {\n if (s1.empty()) {\n s1.insert(nums[i]);\n continue;\n }\n if (s1.size() == s2.... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n void add_element(multiset<double>& mini, multiset<double, greater<double>>& maxi, int data){\n mini.insert(data);\n maxi.insert(*mini.begin());\n mini.erase(mini.begin());\n if(maxi.size() > mini.size()){\n mini.insert(*maxi.begin());\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n multiset<int> lo, hi;\n vector<double> medianSlidingWindow(vector<int>& a, int k) {\n vector<double> ret;\n for (int i=0; i<a.size(); ++i) {\n lo.insert(a[i]);\n if ((lo.size()-hi.size()) > 1) {\n hi.insert(*lo.rbegin());\... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "\nclass Solution {\npublic:\n \n vector<double> medianSlidingWindow(vector<int>& v, int k) {\n multiset<int>ms1,ms2;\n vector<double>op;\n bool odd = k%2==1;\n //cout<<odd;\n for(int i=0;i<k;i++){\n cout<<i;\n ms1.insert(v[i]);\n \n if(ms1.size()-ms2.size()>... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\n\n void insertAndBalanceSets(multiset<int> &topMinSet, multiset<int, greater<int>> &topMaxSet) {\n // printSet(topMinSet);\n // printSet(topMaxSet);\n // cout<<endl;\n if(topMaxSet.size() - topMinSet.size() == 2) {\n // cout<<\" size g... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n\n multiset<long long> L;\n multiset<long long> R;\n\n void add(int x){\n if((int)L.size() < (int)R.size()){\n R.insert(x);\n L.insert(*R.begin());\n R.erase(R.begin());\n }else{\n L.insert(x);\n R.inse... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& vec, int k) {\n multiset<double> big, low;\n vector<double> ans;\n\n for (int i=0; i<vec.size(); ++i) {\n if (i >= k) {\n if (low.contains(vec[i-k])) low.erase(low.find(vec[i-k]));\... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n void Balance(multiset<long long>&mst1,multiset<long long>&mst2)\n {\n if(mst1.size()==1&&mst2.empty())\n return;\n\n if(mst1.size()>1&&mst2.empty())\n { long long val= *(mst1.rbegin());\n mst2.insert(val);\n mst1.era... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> medians(nums.size()-k+1, 0); \n for (int i = 0; i < nums.size(); i++) {\n // cout << \"insert \" << nums[i] << endl;\n insert(nums[i]);\n if (... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n std::multiset<int> left;\n std::multiset<int> right;\n int const n = nums.size();\n vector<double> meds(n-k+1,0);\n int i=0;\n bool odd = k %2;\n for(;i<n; ++i){\... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n std::multiset<int> left;\n std::multiset<int> right;\n int const n = nums.size();\n vector<double> meds(n-k+1,0);\n int i=0;\n bool odd = k %2;\n for(;i<n; ++i){\... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& nums, int k) {\n vector<double> res;\n multiset<int> l, r;\n int n = nums.size();\n int left = 0, right = 0;\n auto remove = [&](int x) -> void {\n if (l.find(x) != l.end()) {\n ... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class MedianFinder {\npublic:\n multiset<double> ms1, ms2;\n MedianFinder() {}\n \n void addNum(int num) {\n ms1.insert(num);\n rebalance();\n }\n\n void deleteNum(int num) {\n if(ms2.find(num) != ms2.end()) {\n ms2.erase(ms2.find(num));\n rebala... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "class Solution {\npublic:\n vector<double> medianSlidingWindow(vector<int>& arr, int k) {\n int n = arr.size();\n vector<double> ans;\n multiset<int> low,high;\n for(int i=0;i<n;i++){\n //insertion\n low.insert(arr[i]);\n high.insert(*low.rbeg... |
480 | <p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.</p>
<ul>
<li>For examples, if <code>arr = [2,<u>3</u>,4]</code>, the median is <code>3</code>.</li>
<li>For examples, if <code>... | 3 | {
"code": "/*\t\n\t\n\tconstraints: n == k == 10e5\n\t\n\tMy Approaches:\n\n\tA) Navie: sort every subarray of size k, and find middle and store as answer -> TLE\n\n\tTC: O(n * klogk) => O(10^5 * 10^5(log(10^5))) => will give TLE\n\n\tB) Sets: unique | sorted -> can't use as duplicates are possible in subarray\n\t\n... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n size_t pos;\n while((pos = s.find('-')) != string::npos){\n s.erase(pos, 1);\n }\n \n for(char& c: s){\n c = toupper(c);\n }\n \n if(s.size() < k){\n... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int n=s.length();\n int count=0;\n\n for(int i=0; i<n; i++) {\n if (s[i]>='a' && s[i]<='z') {\n s[i]=s[i]-'a'+'A';\n }\n }\n //transform(s.begin(), s.end()... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int n=s.length();\n int count=0;\n\n transform(s.begin(), s.end(), s.begin(),::toupper);\n\n for(int i=n-1; i>=0; i--) {\n if (count==k && s[i]!='-') {\n count=0;\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int n=s.length();\n int count=0;\n\n transform(s.begin(), s.end(), s.begin(),::toupper);\n\n for(int i=n-1; i>=0; i--) {\n if (count==k && s[i]!='-') {\n count=0;\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n std::string licenseKeyFormatting(std::string s, int k) {\n std::string sigma = s;\n while (std::find(sigma.begin(), sigma.end(), '-') != sigma.end())\n {\n sigma.erase(std::find(sigma.begin(), sigma.end(), '-'));\n }\n if (sigma.s... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n\n string licenseKeyFormatting(string s, int k) {\n int n = s.size(), cnt=0;\n string ans = \"\";\n for(int i = n-1; i>=0;i--){\n if(s[i]== '-'){\n continue;\n }\n if(cnt>0 && cnt%k ==0){\n ans... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int j=0;\n string str=\"\";\n int i;\n for( i=s.length()-1;i>=0;i--)\n { \n if(isalnum(s[i])&& j<k)\n {\n str+=toupper(s[i]);\n j++;\n }\n if(j==k && i... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string res = \"\";\n int c = 0, j = 0;\n \n for (int i = s.size() - 1; i >= 0; i--) {\n if (s[i] != '-') {\n res += toupper(s[i]);\n c++;\n \n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int n = s.length();\n int cnt = (n - count(s.begin(), s.end(), '-')) % k;\n if (cnt == 0) {\n cnt = k;\n }\n string ans;\n for (int i = 0; i < n; ++i) {\n char c =... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 0 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n int c = 0;\n for (auto i : s) c+= i=='-';\n int mod = (s.size()-c)%k;\n string ans;\n int kk=mod;\n if (kk==0) kk =k;\n for (auto i : s){\n if (isalpha(i)||isdigit(i))... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 1 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k)\n {\n string ans;\n int l = s.length();\n int dash = k;\n for(int i = l - 1; i >= 0; --i)\n {\n if(s[i] == '-')\n continue;\n \n if(0 == dash)\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 1 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string str = \"\";\n int n = s.length();\n int cnt=0;\n for(int i = n-1; i>=0; i--){\n \n if(s[i] != '-' && cnt < k){\n str += toupper(s[i]);\n cnt++... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\n public:\n string licenseKeyFormatting(string s, int k) {\n string ans;\n int length = 0;\n\n for (int i = s.length() - 1; i >= 0; --i) {\n if (s[i] == '-')\n continue;\n if (length > 0 && length % k == 0)\n ans += \"-\";\n ans += toupper(s[i]);\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\npublic:\n void reverseStr(string& str)\n {\n int n = str.length();\n for (int i = 0; i < n / 2; i++)\n swap(str[i], str[n - i - 1]);\n }\n \n string licenseKeyFormatting(string s, int k) {\n string result = \"\";\n int counter = 0;\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "#include<string>\nclass Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n \n int n = s.length() ;\n string result ;\n string temp ;\n \n for(int i=n-1 ; i>=0 ; i--){\n char ch = s[i] ;\n if(ch == '-'){\n conti... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n string str = \"\";\n int ctr = 0;\n for(int i=s.size()-1;i>=0;i--)\n {\n if(s[i] != '-')\n {\n str += toupper(s[i]);\n ctr++;\n if(ctr == k)\n {\... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n string l;\n for(int i=0;i<s.length();i++)\n {\n if(s[i]!='-')\n {\n l.push_back(toupper(s[i]));\n }\n }\n reverse(l.begin(),l.end());\n ... |
482 | <p>You are given a license key represented as a string <code>s</code> that consists of only alphanumeric characters and dashes. The string is separated into <code>n + 1</code> groups by <code>n</code> dashes. You are also given an integer <code>k</code>.</p>
<p>We want to reformat the string <code>s</code> such that e... | 2 | {
"code": "class Solution {\npublic:\n string licenseKeyFormatting(string s, int k) {\n\n string l;\n for(int i=0;i<s.length();i++)\n {\n if(s[i]!='-')\n {\n l.push_back(toupper(s[i]));\n }\n }\n reverse(l.begin(),l.end());\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.