id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 3 | {
"code": "class Solution {\npublic:\n void DFS(int u, unordered_map<int, vector<int>>& adj,\n vector<bool>& visited) {\n visited[u] = true;\n\n for (auto v : adj[u]) {\n if (!visited[v]) {\n DFS(v, adj, visited);\n }\n }\n }\n int makeCon... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n int divisor = 1e3;\n int original_num = num;\n while (divisor > 0) {\n int curr = num / divisor;\n if (curr == 6) return original_num + (3 * divisor);\n num %= divisor;\n diviso... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n string str = to_string(num);\n int n = str.size();\n for(int i=0;i<n;i++){\n if((str[i]-'0')==6){\n str[i] = '9';\n break;\n }\n }\n num = stoi(str);\n ... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int itpow(int a, int b){\n int ans = 1;\n int temp = b;\n while(temp){\n if(temp&1){\n ans = ans*a;\n }\n a = a*a;\n temp = temp>>1;\n }return ans;\n }\n int maximum69Number (int num)... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number(int n) {\n string s=to_string(n);\n for(int i=0;i<s.size();i++)\n {\n if(s[i]=='6')\n {\n s[i]='9';\n break;\n }\n }\n return stoi(s);\n }\n};",
"memory"... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n string s = to_string(num);\n for(int i =0; i<s.size(); i++){\n if(s[i] == '6'){\n s[i] = '9';\n break;\n }\n }\n int n = stoi(s);\n return n;\n }\n};",
... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n string numStr = to_string(num);\n for (char& digit : numStr) {\n if (digit == '6') {\n digit = '9';\n break;\n }\n }\n return stoi(numStr);\n }\n};",
"memory... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n string ans = to_string(num);\n for(int i = 0 ; i < ans.size() ; i++){\n if(ans[i] == '9'){\n continue;\n }else{\n ans[i] = '9';\n break;\n }\n ... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 0 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n // T.C O(D) S.C O(D)\n // string s = to_string(num);\n // for(int i =0; i<s.size(); i++){\n // if(s[i] == '6'){\n // s[i] = '9';\n // break;\n // }\n // }\n ... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 1 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n string n = to_string(num);\n for(int i=0;i<n.length();i++)\n {\n if(n[i]=='6')\n {\n n[i]='9';\n break;\n }\n }\n return stoi(n);\n }\n};",
... |
1,448 | <p>You are given a positive integer <code>num</code> consisting only of digits <code>6</code> and <code>9</code>.</p>
<p>Return <em>the maximum number you can get by changing <strong>at most</strong> one digit (</em><code>6</code><em> becomes </em><code>9</code><em>, and </em><code>9</code><em> becomes </em><code>6</c... | 1 | {
"code": "class Solution {\npublic:\n int maximum69Number (int num) {\n string t=to_string(num);\n for(int i=0;i<t.length();i++){\n if(t[i]=='6'){\n t[i]='9';\n break;\n }\n }\n return stoi(t);\n \n }\n};",
"memory": "7700... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 0 | {
"code": "\n#define endl '\\n'\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 vvvin... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 0 | {
"code": "class Solution {\npublic:\n TreeNode* removeLeafNodes(TreeNode* root, int t) {\n if(root->right)root->right = removeLeafNodes(root->right, t);\n if(root->left)root->left = removeLeafNodes(root->left, t);\n if(!root->left && !root->right && root->val == t) return NULL;\n retur... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 3 | {
"code": "auto init = []() {cin.tie(0); ios::sync_with_stdio(0); return 1;}();\nclass Solution {\npublic:\n TreeNode* solve(TreeNode* root, int target) {\n if(!root) return NULL;\n\n\n root->left = solve(root->left, target);\n root->right = solve(root->right, target);\n\n if(!root->lef... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 3 | {
"code": "auto init = []() {cin.tie(0); ios::sync_with_stdio(0); return 1;}();\nclass Solution {\npublic:\n TreeNode* solve(TreeNode* root, int target) {\n if(!root) return NULL;\n\n root->left = solve(root->left, target);\n root->right = solve(root->right, target);\n\n if(!root->left ... |
1,450 | <p>Given a binary tree <code>root</code> and an integer <code>target</code>, delete all the <strong>leaf nodes</strong> with value <code>target</code>.</p>
<p>Note that once you delete a leaf node with value <code>target</code><strong>, </strong>if its parent node becomes a leaf node and has the value <code>target</co... | 3 | {
"code": "class Solution {\npublic:\n TreeNode* solve(TreeNode* root, int target) {\n if(!root) return NULL;\n\n root->left = solve(root->left, target);\n root->right = solve(root->right, target);\n\n if(!root->left && !root->right && root->val == target) return NULL;\n return r... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 0 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int> > st;\n for(int i =0;i<ranges.size();i++){\n pair<int,int>p = make_pair(max(0,i - ranges[i]) , min(n,i+ranges[i]));\n while(st.size() && st.back().second <= p.second && p.firs... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 0 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int> > st;\n for(int i =0;i<ranges.size();i++){\n pair<int,int>p = make_pair(max(0,i - ranges[i]) , min(n,i+ranges[i]));\n while(st.size() && st.back().second <= p.second && p.firs... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 0 | {
"code": "class Solution {\npublic:\n #define MAXN 10001\n #define INFTY 1000000000\n int dp[MAXN], T[4 * MAXN];\n\n struct segment {\n int X, Y;\n } S[MAXN];\n\n static bool compareSegments(segment A, segment B) {\n return A.X < B.X;\n }\n\n void Build(int lo, int hi, int v) {\... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 0 | {
"code": "class Solution {\n /*\n index = 0 1 2 3 4 5\n range = 3 4 1 1 0 0\n left 0 0 1. 2. 4 5\n right. 3 5. 3. 4 4 5\n\n//transition\n dp[i] = min(1+dp[k], dp[i]) ; 0<= k < i\n dp[0] = 0;\n\n dp[n]\n */\npublic:\n int minTaps(int n, vector<int>& ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 0 | {
"code": "#include <ranges>\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n int m = ranges.size();\n vector<int> rightmost(m, 0);\n for(auto [i, range] : ranges | std::views::enumerate) {\n int l = max(0, static_cast<int>(i) - range), r = i + range;\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 0 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<int> dp(n + 1, n + 1);\n dp[0] = 0;\n for (int i = 0; i <= n; i++) {\n int l = max(0, i - ranges[i]), r = min(i + ranges[i], n);\n for (int j = l; j <= r; j++) {\n dp[... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 1 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n \n vector<int> dp(n + 1, 0);\n\n for(int i=0; i <= n; i++) {\n int start = max(0, i - ranges[i]);\n int end = min(n, i + ranges[i]);\n dp[start] = max(dp[start], end - start);\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int solve(int n, const vector<int>& ranges, int pos, vector<int>& dp) {\n if (pos >= n)\n return 0;\n if (dp[pos] != -1)\n return dp[pos];\n int minTaps = INT_MAX;\n for (int i = 0; i <= n; ++i) {\n if (i - ranges[i... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<ll> dp(n+1, INT_MAX);\n dp[0] = 0;\n for(int i = 0; i<=n ; i++){\n ll start = max(0, i - ranges[i]);\n ll end = min(n, i + ranges[i]);\n for(int ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int> ranges) {\n //int d=1;\n // vector<vector<int>>range;\n vector<int>t(n+1,0);\n for (int i = 0; i < ranges.size(); i++) {\n int start = max(0, i - ranges[i]);\n int end = min(n, i + ranges[i]);\n // range.push_back(... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n int hash[n+1];\n for(int i=0;i<=n;i++){\n hash[i]=i;\n }\n sort(hash,hash+n+1,[&ranges](int a,int b){\n if(a-ranges[a]<b-ranges[b]){\n return true;\n }\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<int> ans(n+1);\n for(int i = 0; i <= n; i++){\n ans[i] = i;\n }\n for(int i = 0; i <= n; i++){\n int r = ranges[i];\n int s = max(i-r,0);\n int e = min(n... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<int> ans(n+1);\n for(int i = 0; i <= n; i++){\n ans[i] = i;\n }\n for(int i = 0; i <= n; i++){\n int r = ranges[i];\n int s = max(i-r,0);\n int e = min(n... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> a(n+1);\n for(int i=0;i<=n;i++){\n a[i].first = max(0,i-ranges[i]);\n a[i].second = min(n,i+ranges[i]);\n }\n sort(a.begin(),a.end());\n int ans=0,curr=0... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> tt(n+1);\n for(int i = 0;i<ranges.size();i++)\n {\n int l = max(0,i-ranges[i]);\n int r = min(n,i+ranges[i]);\n tt[i] = {l,r};\n }\n sort(tt.b... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\nint helper(int ind , int n , vector<int>&nums, vector<int>&dp){\n if(ind >=n) return 0;\n if(nums[ind] == 0) return 1e9;\n if(dp[ind] != -1) return dp[ind];\n int temp = 1e9;\n for(int i = ind+1; i<=nums[ind]; i++){\n temp = min(temp , 1 + helper(i,n,nums,dp... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int, int> > a;\n for (int i = 0; i <= n; ++i) {\n if (ranges[i] == 0) continue;\n int l = i - ranges[i], r = i + ranges[i];\n a.push_back({l, r});\n } \n in... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "\nclass Solution {\n struct range {\n int l, r;\n };\n\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector <range> rrs;\n\n for (int i = 0; i <= n; ++i)\n {\n if (ranges [i] == 0) {\n continue;\n }\n\n int r = i ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\n struct range {\n int l, r;\n };\n\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector <range> rrs;\n vector <range> candidates;\n\n for (int i = 0; i <= n; ++i)\n {\n if (ranges [i] == 0) {\n continue;\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\nprivate:\n int call(int index, int prev, int n, vector<int> &area, vector<int> &dp){\n if(prev == n) return 0;\n if(index >= area.size()) return INT_MAX;\n \n if(dp[prev] != -1) return dp[prev];\n\n int val1 = 0, val2 = 0;\n if(index <= prev){\... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int curmax=0; \n bool HasIntersection(pair<int,int>& inter, int cur){\n if(cur>=inter.first && cur<=inter.second){\n return true; \n }\n return false; \n }\n pair<int,int> iterateTillPresent(vector<pair<int,int>>& inter, int cur, in... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> taps;\n\n for(int i =0;i<=n;i++){\n if(ranges[i] == 0) continue;\n taps.push_back({max(0,i-ranges[i]), min(i+ranges[i],n+1)});\n }\n\n sort(taps.begin(),taps.en... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int, int>> v;\n for(int i = 0;i<ranges.size();i++){\n v.push_back({i - ranges[i], i + ranges[i]});\n }\n\n sort(v.begin(), v.end());\n\n // for(int i = 0;i<v.size();i++){\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> v,ans;\n\n for(int i=0;i<ranges.size();i++){\n if(ranges[i]!=0)\n v.push_back({max(0,i-ranges[i]),min(n,i+ranges[i])});\n }\n if(v.size()==0)\n r... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int greedy(int n,vector<pair<int,int>>& v) {\n int i=0,end=0,count=0,maxx=-1;\n while(i<=n){\n maxx = end;\n int flg = 0;\n while(i<=n and v[i].first<=end){\n flg = 1;\n maxx = max(maxx,v[i].second);... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int, int>> intervals;\n for (int i = 0; i < ranges.size(); ++i) {\n intervals.emplace_back(max(0, i - ranges[i]), min(i + ranges[i], n));\n }\n vector<int> farthest(n + 1, 0);\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int, int>> intervals;\n for (int i = 0; i < ranges.size(); ++i) {\n intervals.emplace_back(max(0, i - ranges[i]), min(i + ranges[i], n));\n }\n vector<int> farthest(n + 1, 0);\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& v) {\n vector<array<int, 2>> w;\n for (int i = 0; i < v.size(); i++) {\n if (v[i]) {\n w.push_back({max(0, i - v[i]), min(n, i + v[i])});\n }\n }\n sort(w.begin(), w.end(),\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 2 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n // so for this problem we have in total of n+1, ranges right\n vector<pair<int,int>>v;\n for(int i=0;i<(int)ranges.size();i++){\n v.push_back({max(0,i-ranges[i]),min(n,i+ranges[i])});\n }\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "#include <utility>\n#include <algorithm>\n\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n //Sort intervals from left to right. Remove any ranges within ranges.\n //Then, best option is to pick \"greedily\"\n\n vector<pair<int,int>> inters;\n for(int ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\nprivate: \n bool static mySort(pair<int,int> &a, pair<int,int> &b) {\n return a.first < b.first;\n }\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> vec;\n int end = n;\n cout<<end<<endl;\n for (int i =0;i<ranges.siz... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n vector<pair<int,int>> v;\n\n int dp[10004];\n int rec(int i){\n if(i == v.size()){\n return 1e9;\n }\n if(v[i].second == v.size()-1){\n return 1;\n }\n\n if(dp[i] != -1) return dp[i];\n\n int ans = 1e9;\n\n... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int n, dp[10005];\n int solve(int i, vector<pair<int, int>> &v)\n {\n if(i != -1 && v[i].second >= n)\n return 0;\n\n if(dp[i + 1] != -1)\n return dp[i + 1];\n\n int ans = 1e9;\n for(int j = i + 1; j < v.size(); j++)\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution{\npublic:\n int N;\n long dp[10008];\n long help(int i, vector<pair<int, int>> &vp)\n {\n if (vp[i].second == N)\n return 1;\n if (i == vp.size())\n return INT_MAX;\n if (dp[i] != -1)\n return dp[i];\n long ans = INT_MA... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<array<int, 3>> data;\n for (int i = 0; i < ranges.size(); ++i) {\n if (ranges[i] != 0) {\n array<int, 3> item = {i - ranges[i], i + ranges[i], 0};\n data.emplace_back(ite... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n,vector<int>&ranges) {\n int s=ranges.size();\n vector<pair<int,int>>arr;\n for(int i=0;i<s;i++){\n int left=max(0,i-ranges[i]);\n int right=min(n,i+ranges[i]);\n arr.push_back({left,right});\n }\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n,vector<int>&ranges) {\n int s=ranges.size();\n vector<pair<int,int>>arr;\n for(int i=0;i<s;i++){\n int left=max(0,i-ranges[i]);\n int right=min(n,i+ranges[i]);\n arr.push_back({left,right});\n }\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n const int MAX_N = 10005;\n const int MAX_RANGE = 120;\n int res = n;\n vector<int> F(MAX_N,MAX_N), T(MAX_N,-1);\n for (int i=0;i<ranges.size();i++) {\n if (i-ranges[i]<=0 && ranges[i]!=0... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>>arr;\n for(int i=0;i<=n;i++){\n arr.push_back({i-ranges[i],i+ranges[i]});\n }\n sort(arr.begin(),arr.end());\n queue<pair<pair<int,int>,int>>q;\n int size=arr... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "struct Pair {\n int node, distance;\n Pair(int _n,int _d) : node(_n),distance(_d) {}\n bool operator < (auto& pair) const {\n return node < pair.node;\n }\n};\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> graph;\n\n for(in... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "// Structure to represent a pair of node and its distance\nstruct Pair {\n int node, distance;\n Pair(int _node, int _dist) : node(_node), distance(_dist) {};\n // Custom comparison operator for priority queue\n bool operator < (const Pair& pair) const {\n return node < pair.node;\n }... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "// Structure to represent a pair of node and its distance\nstruct Pair {\n int node, distance;\n Pair(int _node, int _dist) : node(_node), distance(_dist) {};\n // Custom comparison operator for priority queue\n bool operator < (const Pair& pair) const {\n return node < pair.node;\n }... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\n struct range {\n int l, r;\n };\n\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector <range> rrs;\n vector <range> candidates;\n rrs.reserve (40'000);\n candidates.reserve (40'000);\n \n for (int i = 0; i <= n; ++i)\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n\n static bool cmp( pair<int,int> &a, pair<int, int> &b)\n {\n // first value in inc, second val in dec\n if (a.first != b.first) return a.first < b.first;\n return a.second >= b.second;\n }\n\n int func(int ind, vector<pair<int,int>> &v, vector<i... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n map<int,int>mp;\n for(int i=0;i<ranges.size();i++){\n int l = max(i-ranges[i],0);\n int r = min(n,i+ranges[i]);\n mp[l]=max(mp[l],r);\n }\n int ans = 0;\n int currW... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n map<int,int>mp;\n for(int i=0;i<ranges.size();i++){\n int l = max(i-ranges[i],0);\n int r = min(n,i+ranges[i]);\n mp[l]=max(mp[l],r);\n }\n mp[n]=max(mp[n],0);\n in... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n vector<pair<int,int>> v;\n for(int i=0;i<=n;i++){\n int l=max(0,i-ranges[i]);\n int r=min(n,i+ranges[i]);\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n // if no interval starts from i, keep it as 0\n ++n;\n vector<int> range(n+1);\n // this will store max range starting from left to right\n unordered_map<int,int> intervals;\n for(int i=0; i<n; i... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n map<int, int> mp;\n for (int i = 0; i <= n; ++i) {\n int key = max(i - ranges[i], 0);\n mp[key] = max(mp[key], i + ranges[i]);\n // cout << key << \" \" << mp[key] << endl;\n }\n... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n map<int, int> mp;\n for (int i = 0; i <= n; ++i) {\n int key = max(i - ranges[i], 0);\n mp[key] = max(mp[key], i + ranges[i]);\n }\n cout << endl;\n\n stack<pair<int, int>> st... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(const std::vector<int>& a, const std::vector<int>& b) {\n if (a[0] == b[0])\n return a[1] > b[1];\n return a[0] < b[0];\n}\n int minTaps(int n, vector<int>& ranges) {\n \n vector<vector<int>> vec(ranges.size(),vector<int>(2,0));\... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n int ans = 0;\n\n vector<pair<int,int>> intervals;\n for(int i=0;i<ranges.size();i++) {\n if(ranges[i] != 0) {\n intervals.push_back({i-ranges[i],i+ranges[i]});\n }\n }... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<pair<int,int>> intervals(n+1);\n for(int i=0;i<=n;i++){\n intervals.push_back({max(0,i-ranges[i]), min(n,i+ranges[i])});\n intervals.push_back({min(n,i+ranges[i]), min(n,i+ranges[i])});\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int Stitching(vector<vector<int>>& clips, int T) {\n sort(clips.begin(),clips.end());\n for(int i=0;i<T;i++){\n cout<<clips[i][0]<<\" \"<<clips[i][1]<<endl;\n }\n int res = 0;\n for (auto i = 0, st = 0, end = 0; st < T; st = end, ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n // bool Comparator(vector<int>a, vector<int>b){\n // return a[0] < b[0];\n // }\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>>rangearray(n+1, vector<int>(2,0));\n cout << \"n: \" << n << \" ranges.size(): \" << ranges.size() << en... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> nums(n+1);\n for (int i = 0; i <= n; i++) {\n int st = max(0, i - ranges[i]); \n int ed = min(n, i + ranges[i]); \n nums[i] = {st, ed};\n }\n\n sort(nu... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int Stitching(vector<vector<int>>& clips, int T) {\n sort(clips.begin(),clips.end());\n for(int i=0;i<T;i++){\n cout<<clips[i][0]<<\" \"<<clips[i][1]<<endl;\n }\n int res = 0;\n for (auto i = 0, st = 0, end = 0; st < T; st = end, ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>>v(n+1,vector<int>(2));\n for(int i=0;i<=n;i++){\n v[i][0]=i-ranges[i];\n v[i][1]=i+ranges[i];\n }\n sort(v.begin(),v.end());\n vector<int>a(n+1);\n f... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n map<int,int>mp;\n for(int i=0;i<ranges.size();i++){\n int p=max(0,i-ranges[i]);\n int q=min(n,i+ranges[i]);\n\n mp[p]=max(mp[p],q);\n }\n for(auto x:mp){\n cout... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n\n int sol(int i,vector<int> &ranges,int n,vector<vector<int>> &dp,int k){\n if(i>=n){\n return k;\n }\n if(dp[i][k]!=-1){\n return dp[i][k];\n }\n int s=1e9;\n for(int j=i+1;j<=(i+ranges[i]);j++){\n s=... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int solve(int index , map<int , pair<int , int> > & m , vector<int> & ranges){\n if (index <=0){\n return 0 ; \n }\n\n int ans = INT_MAX ; \n if (m[index].first != index){\n int x = solve(m[index].first , m , ranges) ; \n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "bool cmp(vector<int> &dataA, vector<int> &dataB) {\n if (dataA[0] == dataB[0]) {\n return dataA[1] > dataB[1];\n }\n return dataA[0] < dataB[0];\n}\n\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> data;\n int size = ranges.size(... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "bool cmp(vector<int> &dataA, vector<int> &dataB) {\n if (dataA[0] == dataB[0]) {\n return dataA[1] > dataB[1];\n }\n return dataA[0] < dataB[0];\n}\n\nclass Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> data;\n int size = ranges.size(... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& v) {\n \n\n vector<pair<int, int>> vk;\n map<int, int> m;\n for(int i=0; i<=n; i++){\n int p1 = i-v[i];\n int p2 = i + v[i];\n if(p1<0){\n p1 = 0;\n }\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n static bool func(const vector<int>& a, const vector<int>& b)\n {\n if (a[0] != b[0])\n return a[0] < b[0];\n else\n return a[1] > b[1];\n }\n int minTaps(int n, vector<int>& ranges) {\n // at each step, we need to find a tap tha... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n int ans = 0;\n vector<vector<int>> v;\n for(int i=0; i<=n; i++) {\n if(ranges[i]!=0) v.push_back(vector<int>{max(0, i-ranges[i]), min(n, i+ranges[i])});\n }\n if(v.size() == 0) return -1... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n int ans = 0;\n vector<vector<int>> v;\n for(int i=0; i<=n; i++) {\n if(ranges[i]!=0) v.push_back(vector<int>{max(0, i-ranges[i]), min(n, i+ranges[i])});\n }\n if(v.size() == 0) return -1... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n n++;\n\n vector<vector<int>> a;\n\n for (int i=0; i<n; i++) {\n if (ranges[i] == 0) continue;\n\n int left = max(0, i - ranges[i]);\n int right = min(n-1, i + ranges[i]);\n ... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& r) {\n vector<vector<int>> ranges;\n for(int i = 0; i < r.size(); i++) {\n if(r[i] != 0) ranges.push_back({max(0, i-r[i]), min(n, i+r[i])});\n }\n if(!ranges.size() && n > 1) return -1;\n sort(range... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& r) {\n vector<vector<int>> ranges;\n for(int i = 0; i < r.size(); i++) {\n if(r[i] != 0) ranges.push_back({max(0, i-r[i]), min(n, i+r[i])});\n }\n if(!ranges.size() && n > 1) return -1;\n sort(range... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n static bool comp(vector<int> &a,vector<int> &b){\n if(a[0]!=b[0])\n return a[0]<b[0];\n return a[1]>b[1];\n }\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> taps;\n for(int i=0;i<=n;i++){\n taps.push_b... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\n static bool comp(vector<int> &a, vector<int> &b){\n if(a[0]==b[0])return a[1]>b[1];\n\n return a[0]<b[0];\n }\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> interval;\n\n for(int i=0; i<=n; i++){\n interval.push_... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n\n static bool comp(vector<int>& a,vector<int>& b){\n if(a[0] == b[0]){\n return a[1] > b[1];\n }\n\n return a[0]<b[0];\n }\n\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> intervals;\n\n for(int i=0;i<ranges... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> inter;\n for(int i=0;i<=n;i++){\n inter.push_back({max(0,i-ranges[i]),min(n,i+ranges[i])});\n }\n sort(inter.begin(),inter.end());\n int count = 1;\n vector<in... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<vector<int>> intervals;\n for(int i=0;i<ranges.size();i++)\n {\n int left=max(i-ranges[i],0);\n int right=min(i+ranges[i],n);\n intervals.push_back({left,right});\n }\... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n vector<int>back;\n int cnt=1;\n vector<vector<int>>tapRange;\n for(int i=0;i<ranges.size();i++){\n int start=max(0,i-ranges[i]);\n int end=min(n,i+ranges[i]);\n tapRange.p... |
1,451 | <p>There is a one-dimensional garden on the x-axis. The garden starts at the point <code>0</code> and ends at the point <code>n</code>. (i.e., the length of the garden is <code>n</code>).</p>
<p>There are <code>n + 1</code> taps located at points <code>[0, 1, ..., n]</code> in the garden.</p>
<p>Given an integer... | 3 | {
"code": "class Solution {\npublic:\n int minTaps(int n, vector<int>& ranges) {\n \n // 18 mins, thought of a greedy solution\n\n vector <vector <int>> arr;\n\n for (int i = 0; i <= n; i++){\n int start = max (0, i - ranges[i]);\n int end = min (n, i + ranges[i]);... |
2,016 | <p>Given an integer array <code>nums</code>, your goal is to make all elements in <code>nums</code> equal. To complete one operation, follow these steps:</p>
<ol>
<li>Find the <strong>largest</strong> value in <code>nums</code>. Let its index be <code>i</code> (<strong>0-indexed</strong>) and its value be <code>large... | 0 | {
"code": "#pragma GCC optimize(\"O3\")\nclass Solution {\npublic:\n int reductionOperations(vector<int>& nums) {\n int freq[50001]={0};\n int minN=50000, maxN=0;\n #pragma unroll\n for(int x: nums){\n freq[x]++;\n minN=min(minN, x);\n maxN=max(maxN, x);... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.