id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> res;\n int lpref[n];\n int rpref[n];\n\n lpref[0] = nums[0];\n rpref[n-1] = nums[n-1];\n for(int i = 1; i < n ;i++){\n lpref[i]... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int pre[nums.size()];\n int post[nums.size()];\n vector<int> ans;\n pre[0] = nums[0];\n for(int i=1;i<nums.size();i++){\n pre[i] = nums[i]*pre[i-1];\n }\n for(int ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n int left[n], right[n];\n left[0] = 1, right[n-1] = 1;\n for(int i = 1; i < n; i++){\n left[i] = left[i-1]*nums[i-1];\n }\n for(int i = n-2; i >= 0;... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> res;\n int n = nums.size();\n int pf[n];\n int sf[n];\n pf[0] = nums[0];\n sf[n-1] = nums[n-1];\n for(int i=1; i<n; i++){\n pf[i] = pf[i-1]*nums[i];\n ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> answer;\n int prefix[n];\n int suffix[n];\n prefix[0] = 1;\n suffix[n-1] = 1;\n\n for(int i = 1; i < n;i++){\n prefix[i] = prefi... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> res;\n int n = nums.size();\n int pf[n];\n int sf[n];\n pf[0] = nums[0];\n sf[n-1] = nums[n-1];\n for(int i=1; i<n; i++){\n pf[i] = pf[i-1]*nums[i];\n ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> answer;\n int prefix[n];\n int suffix[n];\n prefix[0] = 1;\n suffix[n-1] = 1;\n\n for(int i = 1; i < n;i++){\n prefix[i] = prefi... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> final_array;\n unordered_map<int, int> count_map;\n int prod = 1;\n for(int i : nums){\n if(i != 0 && count_map[0] <= 1){\n prod*=i;\n }\n ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> before;\n vector<int> after(nums.size());\n before.push_back(1);\n after[nums.size() - 1] = 1;\n\n for(int i = 1; i < nums.size(); ++i){\n before.push_back(before[i ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n // int prod = 1;\n // for(int elem:nums) {\n // prod = prod*elem;\n // }\n int end = nums.size();\n\n deque<int> inc;\n stack<int> dec;\n inc.push_front(nums[0]);\... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n // int prod = 1;\n // for(int elem:nums) {\n // prod = prod*elem;\n // }\n int end = nums.size();\n\n deque<int> inc;\n stack<int> dec;\n inc.push_front(nums[0]);\... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n=nums.size();\n vector<int> prefix(n),suffix(n);\n prefix[0]=nums[0];\n for(int i=1;i<n;i++){\n prefix[i]=prefix[i-1]*nums[i];\n }\n vector<int> nums2(n);\n f... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> ret(nums.size(), 1);\n int n=nums.size();\n vector<int> pre(n,1);\n vector<int> suff(n,1);\n\n pre[0]=1;\n suff[n-1]=1;\n for(int i=1; i<n;i++){\n pre[... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\nvector<int> productExceptSelf(vector<int> nums)\n{\n int n = nums.size();\n vector<int> res(n);\n vector<int> prefix(n);\n int pre = 1;\n for (int i = 0; i < n; i++)\n {\n prefix[i] = pre;\n pre *= nums[i];\n }\n\n int pos = 1;\n vector<in... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> ret(nums.size(), 1);\n int n=nums.size();\n vector<int> pre(n,1);\n vector<int> suff(n,1);\n\n pre[0]=1;\n suff[n-1]=1;\n for(int i=1; i<n;i++){\n pre[... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int size = nums.size();\n vector<int> ret_vct(size);\n vector<int> l(size);\n l[0] = 1;\n vector<int> r(size-1);\n r.push_back(1);\n for(int i = 1; i < size; i++) {\n ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n vector<int> pre(n,1);\n vector<int> pos(n,1);\n vector<int> ans;\n int prod = 1;\n for(int i =0; i < n; i++)\n {\n pre[i] = prod;\n p... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n = nums.size();\n\n vector<int>p(n+1, 1), s(n+1, 1), ans;\n\n for(int i=0;i<n;i++){\n p[i+1] = p[i]*nums[i];\n }\n for(int i=n-1;i>=0;i--){\n s[i] = s[i+1]*nums... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> ans;\n vector<int> pre = nums;\n vector<int> suf = nums;\n pre[0]=1;\n suf[nums.size()-1]=1;\n for(int i=1 ; i<nums.size(); i++){\n pre[i] = nums[i-1] * pre[i... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int x=nums.size()-1;\n vector<int>left(x+1);\n left[0]=1;\n for(int i=1;i<nums.size();i++){\n left[i]=left[i-1]*nums[i-1];\n }\n vector<int>right(x+1);\n right[x]=... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n int n=nums.size();\n vector<int>pref(n),suff(n);\n vector<int> ans;\n pref[0]=1;\n for(int i=1;i<n;i++){\n pref[i]=pref[i-1]*nums[i-1];\n }\n suff[n-1]=1;\n ... |
238 | <p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[i]</code>.</p>
<p>The product of any prefix or suffix of <code>nums</code> is <strong>... | 3 | {
"code": "class Solution {\npublic:\n vector<int> productExceptSelf(vector<int>& nums) {\n vector<int> answer = {};\n int i = 0;\n int* pre = new int[nums.size()];\n int* post = new int[nums.size()];\n pre[0]=1; post[nums.size()-1]=1;\n for(int i=1; i<nums.size(); i++) {\... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2,tune=native\")\n\nclass Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n ios_base::sync_with_stdio(false);\n cout.tie(0);\n cin.tie(0);\n\n short q[nums.size()];\n unsigned l = 0... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "// Enable aggressive compiler optimizations\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx2,tune=native\")\n\n// Initialize the environment\nbool init() {\n // Disable synchronization with C streams for faster I/O\n ios_base::sync_with_stdio(false);\n // Untie cout from cin to reduce f... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"arch=native\")\nclass Solution {\n using out_t = std::vector<int>;\n\n static bool init() noexcept \n {\n ios::sync_with_stdio(0);\n cin.tie(0);\n return true;\n }\n static inline bool initialized = init();\n\npublic:... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"arch=native\")\nclass Solution {\n using out_t = std::vector<int>;\n\n static bool init() noexcept \n {\n ios::sync_with_stdio(0);\n cin.tie(0);\n return true;\n }\n static inline bool initialized = init();\n\npublic:... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"arch=native\")\nclass Solution {\n using out_t = std::vector<int>;\n\n static bool init() noexcept \n {\n ios::sync_with_stdio(0);\n cin.tie(0);\n return true;\n }\n static inline bool initialized = init();\n\npublic:... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int l =0,r =0;\n int st[nums.size()];\n\n for (int i = 0;i<k;i++){\n while (r>l && nums[st[r-1]]< nums[i]){\n r--;\n }\n st[r++] = i;\n }\n\n... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "// class Solution {\n// public:\n// vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n// priority_queue<pair<int, int>> pq;\n \n// vector<int> ans;\n// ans.reserve(nums.size() - k+1);\n// for(int i=0; i<nums.size(); ++i)\n// {\n// pq.pu... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n=nums.size();\n int next[n];\n stack<int> st;\n st.push(n-1);\n next[n-1]=n;\n for(int i=n-2;i>=0;i--){\n while(st.size()>0 && nums[i]>=nums[st.top()]){\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n=nums.size();\n int next[n];\n stack<int> st;\n st.push(n-1);\n next[n-1]=n;\n for(int i=n-2;i>=0;i--){\n while(st.size()>0 && nums[i]>=nums[st.top()]){\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "\n#define pint pair<int, int>\n#define vint vector<int>\n#define vll vector<long long>\n#define vpint vector<pair<int, int>>\n#define vstr vector<string>\n#define uset unordered_set\n#define umap unordered_map\n#define vbool vector<bool>\n#define vvint vector<vector<int>>\n#define vvvint vector<vector<vect... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans(n-k+1,0);\n stack<int> st; \n for(int i = 0 ;i<n;i++){\n while(!st.empty() && nums[st.top()]<nums[i]){\n int temp = st.top()... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "#define pb push_back\nclass Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> v(nums.size()-k+1);\n deque<int> a;\n a.push_back(10001);\n for(int i = 0 ; i < k ; i++)\n {\n while(*a.rbegin() < nums[i])\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution\n{\npublic:\n std::vector<int> maxSlidingWindow(const std::vector<int> &nums, int k)\n {\n std::vector<int> result;\n if(nums.size() > k + 1)\n {\n result.reserve(nums.size() - k - 1);\n }\n std::vector<int> window;\n window.reserve(... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution\n{\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k)\n {\n vector<int> result;\n result.reserve(nums.size() - k + 1);\n\n //queue<size_t> qmax;\n deque<size_t> qmax = init_start_window(nums.begin(), nums.begin() + k);\n result.push_bac... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n if(k == 1) return nums;\n int m = 0;\n int l = 0, r = k - 1;\n for(int i = 1; i <= r; i++){\n if(nums[i] >= nums[m]) m = i;\n }\n vector<int> ans;\n while(r ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n vector <int> res;\n\n if(n == 0)\n return res;\n if(k == 1)\n return nums;\n\n int left[n]; \n int right[n]; \n\n left[0] =... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans(n-k+1);\n \n stack<int> st;\n vector<int> nextGreaterIndex(n);\n int j = n-1;\n while(j>=0)\n {\n while(st.siz... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n //can we do this in O(n) time using something as dequeu,let's try\n //priority_queue ke similar hai,index hi store karwayenge taaki bahar phek de ,but we will also utilize 1 more key point here\n //if a... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 0 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n\tdeque<int> dq;\n\tvector<int>ret;\n\tfor(int i=0;i<n;i++){\n\t\twhile(!dq.empty() && dq.front()<=i-k) dq.pop_front();\n\t\twhile(!dq.empty() && nums[dq.back()]<=nums[i]) dq.pop_back();\n\t\... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<int> dq;\n int i, j, n = nums.size();\n vector<int> ans;\n i = j = 0;\n // storing the first window\n while(j < k){\n if(dq.empty()){\n dq.push... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<int>maxi;\n deque<int>mini;\n vector<int>ans1;\n for(int i=0;i<k;i++){\n while(!maxi.empty() && nums[maxi.back()]<=nums[i]){\n maxi.pop_back();\n }\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int> &nums, int k) {\n if (k == 1 || nums.size() <= 1) return nums;\n\n vector<int> ans;\n deque<int> D;\n\n int start = 0;\n for (int i = 0; i < nums.size(); i++) {\n while (!D.empty() && D.fro... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> sol;\n deque<pair<int, int>> max;\n for(int i = 0; i < k; ++i){\n removeLowerVals(max, nums[i], i);\n }\n sol.push_back(max.front().first);\n int l = 0;... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n // Solution 2-Monotonous queue: O(n) and O(n)\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> ret;\n for(int i = 0; i < nums.size(); i++){\n pushIntoMonotoneQ(nums[i]);\n if(i >= k-1) {\n ret.push_... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\nprivate:\n deque<int> dic;\n vector<int> output;\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n for(int i = 0; i < k; ++i)\n {\n while(!dic.empty() && nums[i] > nums[dic.back()])\n {\n dic.pop_back();\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int> &nums, int k){\n vector<int> pge(nums.size(), -1), nge(nums.size(), nums.size()); //store prev >= & next > elements\n stack<int> st; //monotonically dec. stack\n for (int i = 0; i < nums.size(); ++i){\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> res;\n if(nums.empty() || k == 0) {\n return res;\n }\n \n deque<int> work;\n \n auto push_num = [&work, nums](int i) {\n while(work.s... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n\n for (int idx = 0; idx < nums.size(); ++idx) {\n update_window(nums[idx], idx, window_left_idx);\n \n if (idx - window_left_idx + 1 == k) {\n auto max = window.f... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n struct InWindow {\n int value;\n int vanish_index;\n\n bool operator<(const InWindow& b) const {\n return value < b.value;\n }\n };\n\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n std::vector<InWindow> in_wind... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<int> deq;\n vector<int> maxofWindow;\n\n if (nums.size() == 0) {\n return {};\n }\n for (int end = 0; end < nums.size(); end++) {\n if (!deq.empty() && de... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n // Using PQ TC->(NlogK)\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>ans;\n priority_queue<pair<int,int>>pq;\n for(int i=0;i<n;i++){\n while(!pq.empty() && pq.top().first<=nums[i]){\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "#include <queue>\n#include <unordered_map>\n#include <climits>\n#include <functional>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, less<int>> pq;\n // unordered_map<int, int> rm;\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n priority_queue<int, vector<int>, function<bool(int, int)>> pq([&nums](int l, int r){return nums[l]<nums[r];});\n vector<bool> visible(nums.size(), false);\n vector<int> ans;\n for (int i = ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n\n // 1 3 -1 -3 5 3 6 7\n // k = 3\n // 3 3 -1\n // p1-> 0 (ith) p2 -> 2(ith + k -1)\n // p1-> 1 index p2 -> 3 index\n // 3 -3 = 3\n // p1-> 2 p2-> 4\n // -1 5 = > 5\n // ith +k + k- 1\n // for finding k max values i am k opeartions\n\n vector<... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n priority_queue< pair < int , int> > q;\n vector<int> ans;\n int n = nums.size();\n for(int i=0 ; i<k ; i++){\n if(!q.empty() and q.top().first > nums[i]){\n q.push... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 2 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<pair<int, int>> queue;\n vector<int> ans;\n int maxi = -1999999;\n int pos = -1;\n for(int i=0;i<k;i++) {\n if(nums[i]>=maxi){\n maxi = nums[i];\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n\n if(k == 1)\n return nums;\n\n vector<int> res;\n priority_queue<pair<i... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n\n if(k == 1)\n return nums;\n\n vector<int> res;\n priority_queue<pair<i... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int>ans;\n priority_queue<pair<int,int>>p;\n \n for(int i=0;i<nums.size();i++){\n p.push({nums[i],i});\n if(i>=k-1){\n int d=i-k;\n while(... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> ans;\n priority_queue<pair<int,int>>pq;\n for(int i=0; i<k;i++)pq.push({nums[i], i});\n ans.push_back(pq.top().first);\n for(int i=k; i<nums.size();i++){\n pq.... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n \n int pos = 0;\n int maxi = 0;\n priority_queue<pair<int,int>>q;\n for(int i=0;i<k;i++){\n if(nums[i]>maxi){\n maxi = nums[i];\n pos = i;\n }... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<pair<int, int>> dq; // decreasing best \n\t\tvector<int> res;\n\t\tint n = nums.size();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\twhile (!dq.empty() && dq.back().second <= i - k) {\n\t\t\t\tdq.pop_back();... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n int t[400005];\n void build(vector <int>& t, vector <int>& nums, int pos, int l, int r){\n if(l == r){\n t[pos] = nums[l - 1];\n return;\n }\n int mid = (l + r) >> 1;\n build(t, nums, pos << 1, l, mid);\n build(t, nu... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> ans;\n stack<int> s1, s2, mx1, mx2;\n for (int i = 0; i < k; i++){\n s2.push(nums[i]);\n if (mx2.empty()){\n mx2.push(nums[i]);\n }\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n #define pp pair<int,int> \n // Push into back stack while maintaining the max in the back stack\n void enq(stack<pp> &front, stack<pp> &back, int value, int &currmax) {\n if(back.empty()){\n back.push({value, value});\n currmax = value;\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class MaxQueue {\npublic:\n MaxQueue() {\n\n }\n \n int max_v() {\n if (!push_stack.empty() && !pop_stack.empty()) {\n return max(push_stack.top().second, pop_stack.top().second);\n } else if (!push_stack.empty()) {\n return push_stack.top().second;\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n if(k == 1) return nums;\n deque<int> dq;\n for(int i = k -1; i >=0 ; i--){\n if(dq.empty() || nums[dq.front()] < nums[i] ) {\n dq.push_front(i);\n }\n }... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n std::priority_queue<int> maxHeap;\n int l = 0;\n vector<int> res;\n unordered_map<int,int> lazyDelete;\n for (int r = 0; r < nums.size(); r++) {\n if (r - l + 1 > k) {\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<int> dq;\n vector<int> ans;\n\n dq.push_front(nums[k - 1]);\n \n for (int i = k - 2; i >= 0; i--) {\n if (dq.size() > 0 and dq.front() <= nums[i]) dq.push_front(nums... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Compare {\npublic:\n bool operator()(pair<int,int>a,pair<int,int>b)\n {\n if ( a.second< b.second) \n {\n return true;\n }\n return false;\n }\n};\n\nclass Solution {\npublic:\n \n \n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n prio... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "\nclass Solution\n{\npublic:\n vector<int> maxSlidingWindow(vector<int> &nums, int k)\n {\n int n = nums.size();\n int s = 0, e = 0;\n priority_queue<int> pq; \n unordered_map<int, int> freq_map; \n vector<int> ans;\n\n while (e < n)\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution\n{\npublic:\n vector<int> maxSlidingWindow(vector<int> &nums, int k)\n {\n int n = nums.size();\n int s = 0, e = 0;\n priority_queue<int> pq;\n unordered_map<int, int> m;\n vector<int> ans;\n\n while (s <= e && e < n)\n {\n\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution{\npublic:\n vector<int>maxSlidingWindow(vector<int>&arr, int k){\n vector<int>ans;\n deque<int>dq;\n for(int i=0; i<arr.size(); i++){\n if(!dq.empty() and dq.front()<=i-k)dq.pop_front();\n while(!dq.empty() and arr[dq.back()]<=arr[i])dq.pop_back(... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n \n vector<int> ans;\n \n deque<int> q;\n \n for(int i=0;i<k-1;i++)\n {\n if(q.empty())\n {\n q.push_front(i);\n }\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n \n map<int,int>mpp;\n\n priority_queue<int> q;\n\n vector<int>ans;\n\n for(int i=0;i<k;i++){\n mpp[nums[i]]++;\n\n q.push(nums[i]);\n }\n\n ans.pu... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n// this solution is written and created by me all of it no help\n void print(priority_queue<int>q)\n {\n while(!q.empty())\n {\n cout<<q.top()<<\" \";\n q.pop();\n }\n cout<<endl;\n }\n ve... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = INT_MIN;\n vector<int> res;\n priority_queue<int> pq;\n map<int,int> count;\n for(int i=0;i<k;i++){\n count[nums[i]]++;\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n vector<int> ans;\n int maxi = INT_MIN;\n int end = 0;\n unordered_map<int, int> mp;\n\n while (end < k) {\n maxi = max(maxi, nums[end]);\n mp[nums[end]]++;\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n unordered_map<int,int> counts;\n vector<int> output;\n int maxx=INT_MIN,n=nums.size();\n for(int i=0;i<k;i++)\n {\n maxx=max(maxx,nums[i]);\n counts[nums[i]]++;... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<pair<int,int>> q;\n vector<int> ans;\n for(int i=0;i<nums.size();i++){\n while(!q.empty() && q.front().second+k <= i ) q.pop_front();\n if(!q.empty()){\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\n void insertEle(deque<pair<int,int>> & dq, vector<int> &nums, int i){\n if(!dq.size() || dq.front().first <= nums[i] ){\n dq.clear();\n dq.push_front({nums[i],i});\n }\n else{\n while(dq.size() && dq.back().f... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n // priority_queue<pair<int,int>> s;\n deque<pair<int,int>> dq;\n auto insertEle = [&](int i){\n if(!dq.size() || dq.front().first <= nums[i] ){\n dq.clear();\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& arr, int k) {\n int n = arr.size();\n vector<int> ans;\n int i = 0, j = 0;\n priority_queue<int> pq;\n unordered_map<int, int> mp;\n\n while (j < n) {\n if ((j - i) < k) {\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n //can I use nge concept here?\n deque <int> q;\n for(int i=k-1;i>=0;i--){\n if(q.empty()){\n q.push_back(i);\n }else if(nums[i]>=nums[q.back()]){\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> ans;\n \n map<int, int, greater<int>> freqMap;\n int i=0, j=0;\n while(j-i<k){\n freqMap[nums[j]]++;\n j++;\n }... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n map<int,int>mp;\n vector<int>ans;\n for(int i=0;i<k-1;i++)\n {\n mp[nums[i]]=i;\n }\n for(int i=k-1;i<nums.size();i++)\n {\n mp[nums[i]]=i;\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "#include <span>\n#include <format>\n\nclass Compare {\npublic:\n bool operator()(const pair<int, size_t> &a, const pair<int, size_t> &b) {\n return a.first < b.first;\n }\n};\n\nclass Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n auto N = nums.size();\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n priority_queue<pair<int, int>> maxPq;\n priority_queue<pair<int, int>, vector<pair<int, int>>,\n greater<pair<int, int>>>\n minPq;\n int n = nums.size();\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "#include <algorithm>\n#include <queue>\n#include <unordered_map>\n\nclass MapHeap {\nprivate:\n std::priority_queue<int> maxHeap; // Max heap to store values\n std::unordered_map<int, int> countMap; // Map to store counts of each value\n\npublic:\n // Add a value to the heap\n void add(int valu... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n unordered_map<int, int> map;\n int current_max = INT_MIN;\n std::vector<int> result;\n\n for (int i = 0; i < k; ++i) {\n map[nums[i]]++;\n current_max = max(nums[i], c... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& arr, int k) {\n if(k == 1) return arr;\n int n = arr.size();\n deque<int> q;\n for(int i = 0 ; i < k-1 ; ++i)\n {\n if(q.empty()) \n {\n q.push_front(0);\n continue;\n }\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> st;\n vector<int> lazy;\n void propagate(int i,int l,int r){\n if(lazy[i] != 0){\n st[i] = max(lazy[i],st[i]);\n if(l != r){\n lazy[2*i+1] = max(lazy[2*i+1],lazy[i]);\n lazy[2*i+2] = max(lazy[2*i+2],... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "#include <algorithm>\n#include <queue>\n#include <unordered_map>\n\nclass MapHeap {\nprivate:\n std::priority_queue<int> maxHeap; // Max heap to store values\n std::unordered_map<int, int> countMap; // Map to store counts of each value\n\npublic:\n // Add a value to the heap\n void add(int valu... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n //priority queue to keep track of the largest elements in k-subset\n //what happens when the sliding window has to remove that largest element?\n //we need a second priority queue that keeps track... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n deque<pair<int, int>>q;\n vector<int>res;\n int n = nums.size();\n\n for(int i = 0; i < k; i++)\n {\n if(q.size() == 0)q.push_front({nums[i], i});\n else\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n std::deque<std::pair<int, int>> rollingMaxes;\n std::vector<int> result;\n\n for (int i = 0; i < nums.size(); ++i) {\n while (!rollingMaxes.empty() && rollingMaxes.back().second <= i-k)... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n int n = nums.size();\n deque<pair<int,int>> dq;\n vector<int> ans; \n for(int i = 0; i<n; i++){\n while(!dq.empty() && dq.front().second<=i-k){\n dq.pop_front();\n }\n ... |
239 | <p>You are given an array of integers <code>nums</code>, there is a sliding window of size <code>k</code> which is moving from the very left of the array to the very right. You can only see the <code>k</code> numbers in the window. Each time the sliding window moves right by one position.</p>
<p>Return <em>the ma... | 3 | {
"code": "class Solution {\npublic:\n vector<int> maxSlidingWindow(vector<int>& nums, int k) {\n std::deque<std::pair<int, int>> rollingMaxes;\n // for (int i = 0; i < k-1; ++i) {\n // if (rollingMaxes.empty() || nums[i] >= rollingMaxes.back().first) {\n // rollingMaxes.pus... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.