id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,181 | <p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> leftmostBuildingQueries(vector<int>& heights, vector<vector<int>>& queries) {\n int n = heights.size(), qn = queries.size();\n vector<vector<vector<int>>> que(n);\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> h;\n ... |
3,181 | <p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> leftmostBuildingQueries(vector<int>& A, vector<vector<int>>& queries) {\n int n = A.size(), qn = queries.size();\n vector<vector<vector<int>>> que(n);\n priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> h;\n vector<... |
3,181 | <p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i <... | 3 | {
"code": "class Solution {\n #define ll long long\n #define pll pair<ll, ll>\npublic:\n vector<int> leftmostBuildingQueries(vector<int>& a, vector<vector<int>>& q) {\n ll n = a.size(), m = q.size();\n vector<int> ans(m, -1);\n\n unordered_map<ll, vector<pll>> mp;\n set<pll> s;\n\... |
3,181 | <p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i <... | 3 | {
"code": "class Solution {\n #define ll long long\n #define pll pair<ll, ll>\npublic:\n vector<int> leftmostBuildingQueries(vector<int>& a, vector<vector<int>>& q) {\n ll n = a.size(), m = q.size();\n vector<int> ans(m, -1);\n\n map<ll, vector<pll>> mp;\n multiset<pll> s;\n\n ... |
3,181 | <p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> H;\n vector<vector<int>> Q;\n vector<vector<int>> Pa;\n vector<int> D;\n\n \n\n vector<int> leftmostBuildingQueries(vector<int>& heights, vector<vector<int>>& queries) {\n \n H = heights;\n int n = H.size();\n Q = queries... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int>ans;\n int n = words.size();\n for(int i =0;i<n;i++ ){\n for(auto j:words[i]){\n if(j==x){\n ans.push_back(i);\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> ans;\n\n for (int i = 0; i < words.size(); i++)\n {\n for(int j = 0; j < words[i].length(); j++)\n {\n if (words[i][j] == x)\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int>vec;\n for(int i=0;i<words.size();i++)\n {\n if(words[i].contains(x))\n {\n vec.push_back(i);\n }\n }\n return vec;... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> ans;\n\n for (int i = 0; i < words.size(); ++i)\n {\n bool contains = false;\n for (int j = 0; j < words[i].size() && !contains; ++j)\n {\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> found;\n for(int word = 0;word<words.size();word++){\n int i = words[word].find(x);\n if(i!=string::npos){\n found.push_back(word);\n }... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> found;\n for(int word = 0;word<words.size();word++){\n int i = words[word].find(x);\n if(i!=string::npos){\n found.push_back(word);\n }... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int>res;\n for(int i=0;i<words.size();i++){\n for(auto ch:words[i]){\n if(ch==x){\n res.push_back(i);\n break;\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 0 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> found;\n for(int word = 0;word<words.size();word++){\n int i = words[word].find(x);\n if(i!=string::npos){\n found.push_back(word);\n }... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 1 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n int n = words.size();\n vector<int>ans = {};\n for(int i = 0; i < n; i++){\n for(int j = 0; j < words[i].size(); j++){\n if(words[i][j] == x){\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 1 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> ans;\n for(int i=0; i<words.size(); i++){\n for(int j=0; words[i][j]!='\\0'; j++){\n if(words[i][j]==x){\n ans.push_back(i);\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> ans;\n for(int i = 0; i<words.size(); i++){\n for(char c : words[i]){\n if (c == x){\n ans.push_back(i);\n break;\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> ans;\n int n = words.size();\n for(int j = 0; j<n;j++){\n for(auto i: words[j]){\n if(i == x){\n ans.push_back(j);\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 3 | {
"code": "class Solution {\npublic:\n std::vector<int> findWordsContaining(const std::vector<std::string>& words, char x) {\n std::vector<int> indexes{};\n\n for (int index{}; std::string_view word : words) {\n if (word.contains(x))\n indexes.emplace_back(index);\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int>ans;\n for(int i=0;i<words.size();i++)\n {\n string s=words[i];\n for(int j=0;j<s.length();j++)\n {\n if(s[j]==x)\n {\n ans... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int> v;\n for(int i=0;i<words.size();i++){\n string s=words[i];\n for(int j=0;j<s.length();j++){\n if(s[j]==x){\n v.push_back(i);\n ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n int n = words.size();\n vector<int>ans;\n for(int i=0;i<n;i++)\n {\n string s =words[i];\n for(int j=0;j<s.size();j++)\n {\n if(s[j] ... |
3,194 | <p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</st... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findWordsContaining(vector<string>& words, char x) {\n vector<int>ans;\n int n = words.size();\n for(int i = 0; i < n; i++){\n string s = words[i];\n for(int j =0; j< s.size(); j++){\n if(x == words[i][j]){... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 0 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n ranges::sort(hBars);\n ranges::sort(vBars);\n int cur = 1, mx1 = 2, mx2 = 2;\n for (int i = 1; i < (int) hBars.size(); i++) {\n if (hBars[i] - hBars[i -... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 0 | {
"code": "class Solution {\npublic:\n int findLongestConsecutive(vector<int>& nums) {\n int result = 0, temp = 0;\n int n = nums.size();\n for (int i = 1; i < n; i++) {\n if (nums[i] - nums[i-1] == 1) temp++;\n else {\n result = max(result, temp);\n ... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 0 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& h, vector<int>& v) {\n int ans, L = 2, R = 2, maxL = 2, maxR = 2;\n sort(h.begin(), h.end());\n sort(v.begin(), v.end());\n for(int i = 0; i < h.size() - 1; i++){\n if(h[i] == h[i + 1... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 1 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n int l1=1,l2=1;\n int cnt=1;\n sort(hBars.begin(),hBars.end());\n sort(vBars.begin(),vBars.end());\n for(int i=1;i<hBars.size();i++){\n if(hBars[i... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 2 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n int h = hBars.size();\n int v = vBars.size();\n \n sort(hBars.begin(),hBars.end());\n sort(vBars.begin(),vBars.end());\n \n int mxh = 1, mxv =... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 2 | {
"code": "class Solution {\npublic:\n int getMaxGap(vector<int>bars){\n sort(bars.begin(),bars.end());\n int count = 2,res=2;\n for(int i=1;i<bars.size();i++){\n count = (bars[i-1]+1==bars[i])? count+1 : 2;\n res = max(res,count);\n }\n return res;\n }\n\n int maximizeSq... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 2 | {
"code": "class Solution {\npublic:\n int getMaxGap(vector<int> bars){\n sort(bars.begin(), bars.end());\n int count = 2, res = 2;\n for(int i = 1; i < bars.size(); ++i) {\n count = (bars[i-1]+1 == bars[i])? count + 1: 2;\n res = max(res, count);\n }\n return res;\n }\n\n... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\n int getMaxGap(vector<int> bars){\n sort(bars.begin(), bars.end());\n int count = 2, res = 2;\n for(int i = 1; i < bars.size(); ++i) {\n count = (bars[i-1]+1 == bars[i])? count + 1: 2;\n res = max(res, count);\n }\n return res;\n }\npublic:\n... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\n int getMaxGap(vector<int> bars){\n sort(bars.begin(), bars.end());\n int count = 2, res = 2;\n for (int i = 1; i < bars.size(); i++) {\n count = (bars[i-1]+1 == bars[i])? count + 1: 2;\n res = max(res, count);\n }\n return res;\n }\n public:\... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n vector<int>h;\n vector<int>v;\n sort(hBars.begin(),hBars.end());\n sort(vBars.begin(),vBars.end());\n for(auto i:hBars)\n h.push_back(i);\n ... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n // - - - - - -\n // | | | |\n // enum all possible vertical distance\n // enum all possible horizontal distance\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n unordered_set<int> vs;\n sort(vBars.begin(),... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& h, vector<int>& v) {\n sort(h.begin(),h.end());\n sort(v.begin(),v.end());\n map<int,int> map1;\n long long int ans =-1;\n int x = h.size();\n int y = v.size();\n int i=0;\n... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n set<int> findGaps(vector<int>& bars) {\n set<int> gaps;\n sort(bars.begin(), bars.end());\n int prev = -1, currGap = 1;\n for (int bar : bars) {\n if (prev == -1 || prev + 1 == bar) {\n ++currGap;\n } else {\n ... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& h, vector<int>& v) {\n set<int>s1;\n set<int>s2;\n sort(h.begin(),h.end());\n sort(v.begin(),v.end());\n int ans=0,c=1;\n s1.insert(1);\n s2.insert(1);\n for(int i=1;... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n sort(hBars.begin(),hBars.end());\n sort(vBars.begin(),vBars.end());\n // hBars.emplace(hBars.begin(),1);\n // vBars.emplace(vBars.begin(),1);\n // hBars.pus... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "class Solution {\npublic:\n int maximizeSquareHoleArea(int n, int m, vector<int>& hBars, vector<int>& vBars) {\n int k= min(n+2,m+2);\n int ans=1;\n int h=hBars.size();\n int v=vBars.size();\n if(h==1 || v==1) return 4;\n unordered_map<int,int> hmap;\n un... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "/*\n note:\n 1. is index in xBars in order? could it be [3,2,4]?\n => yes\n \n method:\n 1. counting by sort: O(nlogn)\n the removal of h are independent of v (i.e. any bigest space of h can be used for h)\n => count the max contigous bar of h and v respectly as a and b... |
3,214 | <p>You are given the two integers, <code>n</code> and <code>m</code> and two integer arrays, <code>hBars</code> and <code>vBars</code>. The grid has <code>n + 2</code> horizontal and <code>m + 2</code> vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from <code>1</code>.</p>
<p>You can <strong>r... | 3 | {
"code": "/*\n note:\n 1. is index in xBars in order? could it be [3,2,4]?\n => yes\n \n method:\n 1. counting by sort: O(nlogn)\n the removal of h are independent of v (i.e. any bigest space of h can be used for h)\n => count the max contigous bar of h and v respectly as a and b... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\npublic:\n int dp[1011][2];\n int sol(int i, int n, bool free, vector<int>& prices) {\n if (i >= n)\n return 0;\n\n if (dp[i][free] != -1)\n return dp[i][free];\n\n int ans = 1e9;\n\n if (free) {\n int nextIndex = (i - 1) +... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\npublic:\n int dp[1001] = {0};\n int recur(vector<int>& A, int i) {\n if (i>= A.size())\n return 0;\n if (dp[i] != 0)\n return dp[i];\n\n int ans = INT_MAX;\n for (int j=i+1; j<=2*i+2; ++j)\n ans = min(ans, recur(A, j));\n\... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int n = prices.size();\n int dp[n+1][2];\n memset(dp,-1,sizeof(dp));\n dp[0][0] = 0;\n dp[0][1] = 0;\n dp[1][0] = 1e9;\n for(int i=1;i<=n;i++){\n dp[i][1] = min(dp[i-1][1],dp... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int n = prices.size(), i, j, temp;\n prices.push_back(0);\n for(i = n - 2; i >= 0; i--){\n temp = prices[i + 1];\n for(j = i + 2; j <= min(n, (i + 1) << 1); j++) temp = min(temp, prices[j]);... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\n int dp[1000];\n\n int findMinCost(vector<int>& prices, int i, int n) {\n if (i >= n) {\n return 0;\n }\n if (dp[i] != -1) {\n return dp[i];\n }\n int minCost = INT_MAX;\n\n for (int j = i + 1; j <= 2 * (i + 1); j++) {\... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int num_fruit = prices.size();\n vector<int> dp(num_fruit, INT_MAX);\n dp[num_fruit - 1] = prices[num_fruit - 1];\n for (int i = num_fruit - 2; i >= 0; i--)\n {\n dp[i] = prices[i] + ((2 *... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) \n {\n ios::sync_with_stdio(false); cin.tie(0);\n int n = prices.size();\n vector<int> dp(n+1, INT_MAX);\n dp[n-1] = prices[n-1];\n for (int i = n-2; i >= 0; i --)\n {\n for (int j =... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "class Solution {\n public:\n int minimumCoins(vector<int>& prices) {\n const int n = prices.size();\n vector<int> dp(n + 1, INT_MAX);\n dp[n] = 0;\n\n for (int i = n - 1; i >= 0; --i)\n for (int j = i + 1; j <= min((i + 1) * 2, n); ++j)\n dp[i] = min(dp[i], prices[i] + dp[j]);\n\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "/*\n26 18 6 12 49 7 45 45\n0 1 2 3 4 5 6 7 \ni = 2; j = 3 -> 2+2+1 = 2*i+1\ni = 3; j = 4 -> <= 2*i+1 = 7\n*/\n\nclass Solution {\npublic:\n int minimumCoins(vector<int>& prices) \n {\n int n = prices.size();\n vector<int> dp(n+1, INT_MAX);\n dp[n-1] = prices[n-1];\n f... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 0 | {
"code": "/*\n26 18 6 12 49 7 45 45\n0 1 2 3 4 5 6 7 \ni = 2; j = 3 -> 2+2+1 = 2*i+1\ni = 3; j = 4 -> <= 2*i+1 = 7\n*/\n\nclass Solution {\npublic:\n int minimumCoins(vector<int>& prices) \n {\n ios::sync_with_stdio(false); cin.tie(0);\n int n = prices.size();\n vector<int> dp(n+1, IN... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 1 | {
"code": "/*\n26 18 6 12 49 7 45 45\n0 1 2 3 4 5 6 7 \ni = 2; j = 3 -> 2+2+1 = 2*i+1\ni = 3; j = 4 -> <= 2*i+1 = 7\n*/\n\nclass Solution {\npublic:\n int minimumCoins(vector<int>& prices) \n {\n int n = prices.size();\n vector<int> dp(n+1, INT_MAX);\n dp[n-1] = prices[n-1];\n f... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 1 | {
"code": "/*\n26 18 6 12 49 7 45 45\n0 1 2 3 4 5 6 7 \ni = 2; j = 3 -> 2+2+1 = 2*i+1\ni = 3; j = 4 -> <= 2*i+1 = 7\n*/\n\nclass Solution {\npublic:\n int minimumCoins(vector<int>& prices) \n {\n ios::sync_with_stdio(false); cin.tie(0);\n int n = prices.size();\n vector<int> dp(n+1, IN... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 1 | {
"code": "class Solution {\npublic:\n int n;\n vector<int> dp;\n int solve(int ind,vector<int>& prices){\n if(ind>=n)\n return 0;\n if(dp[ind]!=-1)\n return dp[ind];\n int ans = INT_MAX;\n int x = prices[ind];\n for(int i=ind;i<=2*ind;i++){\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 1 | {
"code": "class Solution {\npublic:\n int n;\n vector<int>dp;\n int solve(int ind,vector<int>&p)\n {\n if(ind >= n)\n return 0;\n if(dp[ind] != -1)\n return dp[ind];\n int ans = INT_MAX;\n int x = p[ind];\n for(int i=ind;i<=2*ind;i++)\n {\n int... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 1 | {
"code": "class Solution {\npublic:\nvector<int> dp;\nint n;\n int minimumCoins(vector<int>& a) {\n a.insert(a.begin(),0);\n n=a.size();\n dp=vector<int> (n,-1);\n return solve(1,a);\n }\n\n int solve(int ind,vector<int>& a){\n if(ind>=n) return 0;\n if(dp[ind]!=-1)... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 1 | {
"code": "class Solution {\npublic:\n int n;\n vector<int> dp;\n int solve(int ind,vector<int>& prices){\n if(ind>=n)\n return 0;\n if(dp[ind]!=-1)\n return dp[ind];\n int ans = INT_MAX;\n int x = prices[ind];\n for(int i=ind;i<=2*ind;i++){\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n const int n = prices.size(); \n // virtual dp[n + 1];\n // dp[i]: minimum coins needed to buy [i:] fruits.\n // dp[i] = min(dp[i], prices[i] + min(dp[j])), j > i and j <= min(2 * (i + 1), n).\n // dp[0] is th... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n const int n = prices.size(); \n // virtual dp[n + 1];\n // dp[i]: minimum coins needed to buy [i:] fruits.\n // dp[i] = min(dp[i], prices[i] + min(dp[j])), j > i and j <= min(2 * (i + 1), n).\n // dp[0] is th... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n deque<pair<short, int>> dq{{-1, 0}};\n // minCoins(k) = dq.top().second after completing i = k\n for(short i = 0; i < prices.size(); ++i) {\n int next = dq.front().second + prices[i];\n if(2 ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int n = prices.size();\n int i=0;\n int sum = 0;\n priority_queue<pair<int,int>>pq;\n for(int i=0;i<n;i++){\n sum = sum + prices[i];\n pq.push({-1*sum,2*i+1});\n whil... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "\nclass Solution {\npublic:\n int minimumCoins(vector<int> &prices) {\n int n = prices.size();\n deque<pair<int, int>> q;\n q.emplace_front(n + 1, 0); // 哨兵\n for (int i = n; i > 0; i--) {\n while (q.back().first > i * 2 + 1) { // 右边离开窗口\n q.pop_back... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int n = prices.size();\n vector<int> dp(n,0);\n int i;\n deque<int> dq;\n for(i = n-1; i>=(n-1)/2; i--){\n dp[i] = prices[i];\n while(dq.size() && dp[dq.back()] >= dp[i]) dq.pop... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices){\n int n = prices.size();\n vector<int> dp(n+1);\n dp[n] = 0;\n deque<int> dq; \n dq.push_back(n);\n for(int i=n-1;i>=0;i--){\n int j = min(n,2*(i+1));\n while(dq.front() > j... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int size = prices.size();\n vector<int> memo(size+1, INT_MAX);\n memo[size] = 0;\n deque<int> minQueue = {size-1};\n for(int i=size-1;i>=0;i--) {\n int freeWindowOverAt = min(2 * i + 1, si... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int i,n=prices.size();\n auto minComp = [&prices](int a, int b){\n return prices[a]>prices[b];\n };\n priority_queue<int, vector<int>, decltype(minComp)> pq(minComp);\n\n for(i=n-1; i>=0; ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n /*\n dp.resize(prices.size(), -1);\n return helper(prices, 1);\n */\n int n = prices.size();\n deque<pair<int, int>> dq;\n dq.emplace_back(n + 1, 0);\n\n for (int i = n; i > 0; -... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n /*\n dp[i][1] = dp[i][0] + p[i];\n dp[i + 1...j][0] = min(dp[i + 1...j][0], dp[i][1]);\n\n dp[0][0] = 27\n dp[0][1] = 27\n\n dp[1][0] = 27\n dp[1][1] = 44\n\n dp[2][0] = 44\n dp[2][1] = 56\n\n dp[3][0] = 44\n dp[3][1] = 89\n\n dp[4][0] = 56\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n int n = prices.size();\n vector<vector<int>> dp(n, vector<int>(2, INT_MAX));\n dp[0][1] = prices[0];\n for (int i = 1; i < n; ++i) {\n dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + prices[i];\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& p) {\n int n = (int) p.size();\n vector<vector<int>> dp(n + 1, vector<int> (2, 1e7));\n dp[0][0] = dp[0][1] = p[0];\n if(n >= 1) {\n dp[1][0] = p[0];\n }\n for(int i = 1; i < n; i++) {\n dp[i][1] = min(dp[i - 1][0], dp[i... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n int minimumCoins(vector<int>& prices) {\n ll n = prices.size();\n if(n==1){\n return prices[0];\n }\n ll max = 1000000007;\n vector<vector<ll> > dp(n+1,vector<ll>(2,max));\n dp[0][0] = prices[0];\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& arr) {\n \n int n = arr.size();\n deque< pair<int,int> > dq;\n\n for( int i=n-1; i>=0; i--) {\n int val = arr[i];\n while((!dq.empty()) && (dq.back().second>i+(i+1)+1)) {\n dq.pop_b... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n\n int solve(vector<int>&prices,int n,vector<vector<int>>&dp,int i,int p){\n if(i>=n)return 0;\n if(i==n-1 and p==0)return prices[i];\n if(i==n-1 and p==1)return 0;\n\n if(dp[i][p]!=-1)return dp[i][p];\n\n int op1=INT_MAX,op2=INT_MAX,op3=INT_MAX;\n... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& nums) {\n deque<pair<int,int>> x;\n vector<int> lol(nums.size(),0);\n lol.back()=nums.back();\n x.push_back({nums.size()-1,nums.back()});\n x.push_back({nums.size(),0});\n\n for(int i=nums.size()-2; i>=0;... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\nint n;\nvector<int>p;\n int minimumCoins(vector<int>& prices) {\n p=prices;\n n=p.size();\n vector<int>dp(n,0);\n deque<int>dq;\n dp[n-1]=p[n-1];\n dq.push_front(n-1);\n for(int i=n-2;i>=0;i--){\n while(!dq.empty()&&d... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution\n{\npublic:\n int minimumCoins(vector<int>& prices)\n {\n // SOL-1: DFS/REC -- TC: O(N^N), SC: O(N) -- 502 / 578 TCs passed -- 86.85%\n // return sol1Rec(prices);\n \n // SOL-2: MEMO -- TC: O(N^2), SC: O(N).\n return sol2Memo(prices);\n }\n\nprivat... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int,int> dp;\n int solve(int i , vector<int> & prices){\n if(i>=prices.size()) return 0;\n if(dp.find(i)!=dp.end()) return dp[i];\n int ans=1e9;\n int n=prices.size();\n for(int j=i+1;j<=min(n,2*i+2);j++){\n ans=m... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "\nint dp[1002][1002];\n\n\nint rec(vector<int> &v,int idx,int free)\n{\n int n = v.size();\n if(idx == n) return 0;\n \n if( dp[idx][free] != -1 ) return dp[idx][free]; \n\n // take\n int ans = 1e9;\n \n if(free > 0) \n {\n ans = min(ans, rec(v,idx+1,free-1));\n ans... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "\nint dp[1002][1002];\n\nclass Solution {\npublic:\n int minimumCoins(vector<int>& v) {\n\n int n = v.size();\n for(int i=0;i<1002;i++) for(int j=0;j<1002;j++) {\n dp[i][j] = 1e9;\n if(i>=n) dp[i][j] = 0;\n }\n\n for(int idx = n-1; idx >= 0 ;idx--)\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1001][1002];\n int helper(int ind, vector<int>& p, int n, int prev){\n if(ind >= n)\n return 0;\n if(dp[ind][prev + 1] != -1)\n return dp[ind][prev + 1];\n int mini = INT_MAX;\n if(ind - prev <= prev + 1)\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1001][1002];\n int helper(int ind, vector<int>& p, int n, int prev){\n if(ind >= n)\n return 0;\n if(dp[ind][prev + 1] != -1)\n return dp[ind][prev + 1];\n int mini = INT_MAX;\n if(ind - prev <= prev + 1)\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1002][1002];\n Solution(){\n memset(dp, -1, sizeof(dp));\n }\n int helper(int curr_cnt, int in, vector<int>& prices, int n)\n {\n if(in == n)\n return 0;\n if(dp[curr_cnt][in] != -1)\n return dp[curr_cnt][in];\n ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int solve(vector<int>& prices, int i, int c){\n if(i>=prices.size()) return 0;\n\n if(dp[i][c]!=-1) return dp[i][c];\n\n int n = prices.size();\n if(c==0) return prices[i] + solve(prices,i+1,i+1);\n int ans = solve(p... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n\n int dp[1002][1002];\n int solve(int idx, int prev_take, vector<int> &prices)\n {\n if(idx==prices.size()) return 0;\n\n if(dp[idx][prev_take+1]!=-1) return dp[idx][prev_take+1];\n\n int take1 = prices[idx] + solve(idx+1,idx,prices);\n int t... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1002][1009];\n int solve(vector<int>&nums,int pos,int isFree){\n if(pos == nums.size()) return 0;\n if(dp[pos][isFree+1]!=-1) return dp[pos][isFree+1];\n int ans = INT_MAX;\n if(pos <= isFree){\n ans = min(ans,solve(nums,pos+1,... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1100][1100];\n\n int func(int i, int count, vector<int> &prices) {\n int n = prices.size();\n\n if (i >= n) return 0;\n\n if (dp[i][count] != -1) return dp[i][count];\n\n int ans = INT_MAX;\n\n ans = min(ans, func(i + 1, i + 1, pri... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\nint dp[1001][1001];\n int f(int i,vector<int>&prices,int n,int prev){\n if(i>=n){\n return 0;\n }\n int take=INT_MAX;\n if(dp[i][prev]!=-1){\n return dp[i][prev];\n }\n\n if(prev!=0){\n take=min({take,p... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\nint f(vector<int> &prices,int i,vector<int> &dp){\n if(i>=prices.size()){\n return 0;\n }\n if(dp[i] != -1){\n return dp[i];\n }\n int mini = INT_MAX;\n for(int j = 1;j<=i+2;j++){\n mini = min(mini,f(prices,i+j,dp));\n }\n\n return dp[... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1001][2004];\n int find(vector<int> &arr,int idx,int range)\n {\n\t if(idx>=arr.size())\n\t\treturn 0;\n\t if(dp[idx][range+1]!=-1)\n\t\treturn dp[idx][range+1];\n\t int temp1=arr[idx]+find(arr,idx+1,idx+idx+1);\n\t int temp2=INT_MAX;\n\t if(idx<=range)\n\t \ttem... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\n int t[1000][2001];\npublic:\n int minimumCoins(vector<int>& prices) {\n memset(t,-1,sizeof(t));\n return f(prices,0,-1);\n }\npublic:\n int f(vector<int>& prices,int ind,int limit)\n {\n int min=INT_MAX;\n if(ind==prices.size())\n return ... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic: \n \n #define ll long long \n ll dp[1004][1004] , n ; \n\n ll solve(int idx , int len , vector<int> &prices){\n \n if(idx>=n)return 0; \n if(dp[idx][len]!=-1) return dp[idx][len]; \n \n if(idx<=len and len!=0){\n ll ans1 =... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\nint dp[1001][2003];\nint solve(int i,int j,vector<int> &prices){\n if(i>=prices.size()) return 0;\n if(dp[i][j+1]!=-1) return dp[i][j+1];\n if(j<i) return dp[i][j+1]=prices[i]+solve(i+1,2*i+1,prices);\n\n return dp[i][j+1]=min(prices[i]+solve(i+1,2*i+1,prices),solve(i... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic: \n \n #define ll long long \n ll dp[1004][1004] , n ; \n\n ll solve(int idx , int len , vector<int> &prices){\n \n if(idx>=n)return 0; \n if(dp[idx][len]!=-1) return dp[idx][len]; \n \n if(idx<=len and len!=0){\n ll ans1 =... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int t[1001][2002];\n int solve(int i,int free,vector<int>& prices)\n {\n if(i>=prices.size())\n return 0;\n\n // if(free>=prices.size())\n // return 0;\n\n if(t[i][free+1]!=-1)\n return t[i][free+1];\n\n int a=1e9,b=a,c=a... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1002][3002];\n int solve(vector<int>&prices,int ind,int range){\n if(range>=prices.size()-1) return 0;\n if(dp[ind][range]!=-1) return dp[ind][range];\n if(ind<=range){\n int take=prices[ind]+solve(prices,ind+1,ind+ind+1);\n int notake=solve(pric... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int dp[1002][3002];\n int solve(vector<int>&prices,int ind,int range){\n if(ind>=prices.size()) return 0;\n if(dp[ind][range]!=-1) return dp[ind][range];\n if(ind<=range){\n int take=prices[ind]+solve(prices,ind+1,ind+ind+1);\n int notake=solve(prices,i... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\nint dp[1001][4001];\nint solve(int id, vector<int>&p, int lim)\n{\n if(id>=p.size())\n return 0;\n if(dp[id][lim]!=-1)\n return dp[id][lim];\n int x=1e8,y=1e8;\n if(id<=lim)\n x=solve(id+1,p,lim);\n y=p[id]+solve(id+1,p,2*id+1);\n\n return dp[id][lim]=m... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int t[2000][2000];\n int solve(vector<int>& prices,int idx,int secondidx){\n if(idx >= prices.size()){\n return 0;\n }\n if(t[idx][secondidx] != -1){\n return t[idx][secondidx];\n }\n int take = prices[idx] + solve(p... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int help(int i, vector<int>& prices,vector<int>& dp){\n int ans=1e9;\n if (i>=prices.size()) return dp[i]=0;\n if (dp[i]!=-1) return dp[i];\n for(int j=1;j<=i+2;j++){\n ans=min(ans,prices[i]+help(i+j,prices,dp));\n }\n retu... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int func(vector<int>& prices,int i, vector<int>& dp){\n if(i>=prices.size())return 0;\n if(dp[i] != -1)return dp[i];\n int res = INT_MAX;\n for(int j=i+1; j<=2*i+2; j++){\n res = min(res,func(prices,j,dp));\n }\n return dp[... |
3,209 | <p>You are given an integer array <code>prices</code> where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following reward for each fruit:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[... | 2 | {
"code": "class Solution {\npublic:\n int minimumCoins(vector<int>& p) {\n int n=p.size();\n vector<int>nxt(n+1);\n for(int rem=0;rem<=n;rem++) nxt[n] = 0;\n for(int ind=n-1;ind>=0;ind--) {\n vector<int>curr(n+1,1e8);\n for(int rem=0;rem<=n;rem++) {\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.