id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int dp[100001]; // Using an array for dp, assuming a maximum length of 100,000\n\n int helper(string& s, int& k, int ind) {\n if (ind >= s.length()) return 1;\n if (dp[ind] != -1) return dp[ind];\n\n int l = 0;\n long lo... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int n; string st; int k1;\n int mod = 1e9+7; int dp[100003];\n\n int rec(int i){\n if(i>=n){\n return 1;\n }\n if(st[i] == '0'){\n return 0;\n }\n if(dp[i] != -1){\n return dp[i];\n }\n lo... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int dp[100001] = {};\n int dfs(string &s , int k , int i ){\n if(i == s.size()) return 1;\n if(s[i] == '0') return 0;\n if(!dp[i]) {\n for(long sz = 1 , num = 0 ; i + sz <= s.size(); ++sz){\n num = num * 10 + s[i + sz-1] -'0';... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n int dp[100100];\n int rec(int i,int n,string &s,int k,ll mod)\n {\n if(i==n)\n return 1;\n ll cur=0;\n if(s[i]=='0')\n return 0;\n if(dp[i]!=-1)\n return dp[i];\n ll ret=0;\n for(i... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\nint n;\nint dp[100001];\n const int mod = 1e9+7;\n int solve(int ind,string &s,int k){\n if(ind==n) return 1;\n\n if(s[ind]=='0') return 0;\n if(dp[ind]!=-1) return dp[ind];\n\n int ways=0;\n long long num=0;\n\n for(int i=ind;i<n;i++)... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\nint M=1e9+7;\nint dp[100001];\nint f(int i,string &s,string &limit,int k1){\n int n=s.size();\nif(i==n){\n return 1;\n}\nif(s[i]=='0'){\n return 0;\n}\nif(dp[i]!=-1){\n return dp[i];\n}\nint ans=0;\nlong long num=0;\nfor(int k=i;k<n;k++){\n num=num*10+s[k]-'0';\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "#include <vector>\n#include <string>\n\nclass Solution {\npublic:\n const int M = 1000000007;\n\n int solve(const string& s, int k, int index,vector<int>& dp) {\n int n = s.length();\n if (index == n) return 1;\n if (s[index] == '0') return 0;\n if (dp[index] != -1) return... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n using ll = long long;\n ll dp[100001];\n ll mod = 1e9+7;\n int f(int i,string &s,int k)\n {\n if(i>=s.size())\n {\n return 1;\n }\n if(s[i]=='0')\n {\n return 0;\n }\n if(dp[i]!=-1)\n {\... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "#define mod 1000000007\nclass Solution {\npublic:\n int rec(int n,int k,string &s,vector<int>&dp)\n {\n int ans = 0,sz =s.size();\n if(n==(sz+1))\n return 1;\n if(dp[n]!=-1)\n return dp[n];\n long long temp = 0;\n for(int i=n;i<=sz;i++)\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "int mod = 1e9+7;\nclass Solution {\n int dfs(int i, string& s, int& k, vector<int>& dp) {\n if(i == s.size()) return 1;\n if(s[i] == '0') return 0;\n if(dp[i] != -1) return dp[i];\n long long num = 0;\n int ans = 0;\n for(int j = i; j < s.size(); j++) {\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n\n int solve(int start, string &s, int k) {\n if (start > s.length()-1) {\n return 1;\n }\n if (dp[start] != -1) {\n return dp[start];\n }\n\n int count = 0;\n long long num = 0;\n\n fo... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int dfs(const string& s,long k,int i,vector<int>& dp){\n if(i==s.size()) return 1;\n if(s[i]=='0') return 0;\n if(dp[i]!=-1) return dp[i];\n \n int ans=0;\n long num=0;\n for(int j=i;j<s.size();j++){\n num=num*10+s[j]-'0';\n... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int dfs(const string& s,long k,int i,vector<int>& dp){\n if(i==s.size()) return 1;\n if(s[i]=='0') return 0;\n if(dp[i]!=-1) return dp[i];\n \n int ans=0;\n long num=0;\n for(int j=i;j<s.size();j++){\n num=num*10+s[j]-'0';\n... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\nprivate:\n int mod = 1e9+7;\n int call(int index, string &s, int &k, vector<int> &dp){\n if(index >= s.length()) return 1;\n if(s[index] - 48 == 0) return 0;\n int ans = 0;\n\n if(dp[index] != -1) return dp[index];\n\n long long num = 0;\n f... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n\n int t[100002],d=1e9+7;\n bool check(int p,int i,string &s,int k)\n {\n long long num=0;\n for(int q=i;q<=p;q++)\n {\n num=10*num+(s[q]-'0');\n }\n\n return num<=k;\n }\n int solve(int i,string &s,int k)\n {\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\nint n;\nint dp[100005];\nconst int mod=1e9+7;\nint f(int start,string &s,int k)\n{\n if(start>=n) return 1;\n if(s[start]=='0') return dp[start]=0;\n if(dp[start]!=-1) return dp[start];\n long ans=0;\n long long num=0;\n for(int end=start;end<n;end++)\n {\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "const int M=1e9+7;\nclass Solution {\npublic:\n int func(int idx, string &s, int k, int n, vector<int>& dp)\n {\n if(idx==n)\n {\n return dp[idx]=1;\n }\n if(dp[idx]!=-1)\n return dp[idx];\n long long res=0, num=0;\n for(int i=idx; i<n; i++)... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int m = 1e9 + 7;\n int n;\n // if next is 0 don't break rn\n // if including the next will make it greater than k then break it\n vector<int> dp;\n int k;\n string s;\n long long int f(long long int indx) {\n if (indx == n)\n return 1;\n... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n #define ll long long\n int len;\n ll dp[100005];\n const int mod=1e9+7;\n ll solve(int i, string &s, int k)\n {\n int n=s.size();\n if(i>=n)\n return 1;\n if(s[i]=='0')\n return 0;\n if(dp[i]!=-1)\n return dp[i];... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int numberOfArrays(string s, int k) {\n int n = s.length();\n vector<long> dp(n), pre(n);\n int mod = 1e9 + 7;\n dp[n-1] = ((s[n-1]-'0') >= 1 and (s[n-1]-'0') <= k);\n pre[n-1] = dp[n-1];\n int d = log10(k);\n for(int i=n-2;i>=... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n int f(int i,string &s,int &k,vector<int> &dp){\n if(i>=s.size())\n return 1;\n if(s[i]=='0')\n return 0;\n\n if(dp[i]!=-1)\n return dp[i];\n long long num=0;\n int ans=0;\n for(int j=i;j<s.siz... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7;\n int solve(string &str,int &k,vector<int> &dp,int &n,int s){\n if(s==n)\n return 1;\n if(str[s]=='0')\n return 0;\n if(dp[s] != -1)\n return dp[s];\n long int y = 0,x = 0;\n for(int i = s... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 1 | {
"code": "class Solution {\npublic:\n\n int solve(int i,string &s,int &k,int &mod,vector<int> &dp){\n if(i>=s.size())\n return 1;\n\n if(dp[i]!=-1)\n return dp[i];\n\n if(s[i]=='0'){\n dp[i]=0;\n return 0;\n }\n \n\n long long ans=0;\n\n long long num=0;\n\n for(int j=i;... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 2 | {
"code": "class Solution {\nprivate:\n int K,mod=1e9+7;\n vector<int> dp;\npublic:\n int dfs(string& s,int index){\n if(index>=s.size()) return 1;\n if(dp[index]!=-1) return dp[index];\n long long num = 0;\n int res=0;\n for(int i=index;i<s.size();i++){\n num = (num*1... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 2 | {
"code": "class Solution {\npublic:\nint mod = 1e9+7;\nint solve(int i,string& s,int &k,vector<int> &dp,int &n){\n if(i>=n)return 1;\n if(s[i]=='0')return 0;\n if(dp[i] != -1)return dp[i];\n long long int x = 0;\n int a = 0;\n for(int j = i; j< n; j++){\n x = x*10+(s[j]-'0');\n if(x<=... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int numWays(int i, string& s, int k, int N, vector<int>& dp)\n {\n int mod = 1e9 + 7;\n if (i == N) {\n return 1;\n }\n\n if (s[i] == '0') {\n return 0;\n }\n\n if (dp[i] != -1) {\n return dp[i];\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int MOD = 1e9 + 7;\n int k;\n int dp[1000001];\n int solve(string& s, int i) {\n if (i >= s.size()) {\n return 1;\n }\n if (s[i] == '0') {\n return 0;\n }\n if(dp[i] != -1){\n return dp[i];\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int dp[1000001];\n\n int f(string &s, int k, int idx) {\n if (idx == s.size()) return 1;\n if (dp[idx] != -1) return dp[idx];\n \n long long num = 0;\n int ways = 0;\n \n for (int i = idx; i < s.size(... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int MOD = 1e9 + 7;\n vector<int> dp;\n int K;\n int N;\n string S;\n\n int find(int lvl){\n int k = K;\n int n = N;\n\n if(lvl == n) return 1;\n if(S[lvl] == '0') return 0;\n if(dp[lvl] != -1) return dp[lvl];\n long lon... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n int n;\n int v[1000001];\n\n int solve(int i, string&s, int &k)\n {\n if( i >= n)\n {\n return 1;\n }\n\n if(v[i] != -1)\n {\n return v[i];\n\n }\n\n if(s[i] == '0')\n {... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n int n;\n int v[1000001];\n\n int solve(int start, string&s, int &k)\n {\n if( start >= n)\n {\n return 1;\n }\n\n if(v[start] != -1)\n {\n return v[start];\n\n }\n\n if(s[start... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\nint n;\nint mod = 1e9 + 7;\nint dp[1000001];\nint solve(string &s, int start, int k) {\n if (start >= n) {\n return 1;\n }\n if (s[start] == '0') {\n return 0; // Leading zeros are invalid\n }\n if(dp[start]!=-1){\n return dp[start];\n }\n ... |
1,517 | <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p>
<p>Given the string <co... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int len;\n int k;\n int res = 0;\n string s;\n int numberOfArrays(string s, int k) {\n // dfs\n this->len = s.size();\n this->k = k;\n this->s = s;\n vector<int> memo(len, -1);\n\n dfs(0, memo);\n\n... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 0 | {
"code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\n\n// Function to extract digit value from a character\nint digit(char c) {\n return c & 15;\n}\n\n// Function to check if a character is a digit\nbool isDigit(char c) {\n return '0' <= c && c <= '9';\n}\... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 0 | {
"code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\n\n// Function to extract digit value from a character\nint digit(char c) {\n return c & 15;\n}\n\n// Function to check if a character is a digit\nbool isDigit(char c) {\n return '0' <= c && c <= '9';\n}\... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 0 | {
"code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\n\n// Function to extract digit value from a character\nint digit(char c) {\n return c & 15;\n}\n\n// Function to check if a character is a digit\nbool isDigit(char c) {\n return '0' <= c && c <= '9';\n}\... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 0 | {
"code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\n\n// Function to extract digit value from a character\nint digit(char c) {\n return c & 15;\n}\n\n// Function to check if a character is a digit\nbool isDigit(char c) {\n return '0' <= c && c <= '9';\n}\... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 0 | {
"code": "int speedUp = [] {\n std::ios::sync_with_stdio(0);\n std::cin.tie(0);\n return 0;\n}();\n\n// Function to extract digit value from a character\nint digit(char c) {\n return c & 15;\n}\n\n// Function to check if a character is a digit\nbool isDigit(char c) {\n return '0' <= c && c <= '9';\n}\... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 1 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int sum = 0;\n int MAX = INT_MIN;\n for (int val : nums) {\n sum += val;\n MAX = max(sum, MAX);\n if (sum < 0) {\n sum = 0;\n }\n }\n return MA... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 1 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n long long maxi=LONG_MIN;\n long long sum=0;\n for(int i=0;i<nums.size(); i++){\n sum+=nums[i];\n if(sum>maxi)\n maxi=sum;\n if(sum<0)\n sum=0; \n }\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int currSum=0,maxvalue=INT_MIN;\n for(int val:nums)\n {\n currSum+=val;\n maxvalue=max(currSum,maxvalue);\n if(currSum<0)\n {\n currSum=0;\n }\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution{\n public:\n int maxSubArray(vector<int>& nums){\n int currSum=0, maxSum=INT_MIN;\n for(int val:nums){\n currSum+=val;\n maxSum=max(currSum,maxSum);\n if(currSum<0){\n currSum=0;\n }\n }\n return max... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int sums[nums.size()];\n sums[0] = max(nums[0], 0);\n \n int largest = nums[0];\n for (int i = 1; i < nums.size(); i++) {\n sums[i] = max(nums[i] + sums[i - 1], 0);\n \n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int n=nums.size();\n int dp[n];\n int mx = nums[0];\n dp[0] = nums[0];\n for(int i=1;i<n;i++){\n if((dp[i-1]+nums[i]) >= nums[i]){\n dp[i] = dp[i-1]+ nums[i];\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int n = nums.size();\n int maxi[n];\n maxi[0] = nums[0];\n for(int i = 1; i < n; i++){\n maxi[i] = max(maxi[i - 1] + nums[i], nums[i]);\n }\n int maxer = -1e9;\n for(int i = 0; ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int count = 0, max_sum = 0, n = nums.size();\n for (int i = 0; i < n; i++) {\n if (nums[i] < 0)\n count++;\n }\n if (count == n) {\n sort(nums.begin(), nums.end());\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int n=nums.size();\n int currentsum=0;\n\n int globalsum=INT_MIN;\n bool flag=false;\n for(int i=0; i<n; i++){\n if(nums[i]>=0){\n flag= true;\n break;\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& v) {\n int dp[100005];\n\n dp[0] = v[0];\n\n int res = -999999999;\n\n for(int i = 0; i < v.size() - 1; i++)\n {\n if(v[i+1] + dp[i] > v[i+1])\n {\n dp[i+1] = dp[i] + v[i+1];\n }\n else\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int sum=0;\n int ans=0;\n for(int i=0;i<nums.size();i++){\n if((sum+nums[i])<0)\n sum=0;\n else\n sum+=nums[i];\n ans=max(ans,sum);\n }\n if(ans==0... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int count = 0, max_sum = 0;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] < 0)\n count++;\n }\n if (count == nums.size()) {\n sort(nums.begin(), nums.end());\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int maxi=INT_MIN;\n int sum=0;\n int n=nums.size();\n for(int i=0;i<n;i++)\n {\n sum+=nums[i];\n if(sum<0)\n sum=0;\n if(sum>maxi)\n maxi=sum;\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n int sum=0;\n int maxi=INT_MIN;\n for(int i=0;i<nums.size();i++){\n \n sum+=nums[i];\n if(sum<0 && nums[i]<0)\n sum=0;\n maxi=max(maxi,sum);\n }... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n if(nums.size() == 1){\n return nums[0];\n }\n int dp[100006][2];\n dp[0][0] = -100000000;\n dp[0][1] = nums[0];\n for(int i = 1; i < nums.size(); i++){\n dp[i][0] = max(dp[i... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int CrossSum(vector<int>&nums,int low,int mid,int high){\n int LSum=INT_MIN;\n int RSum=INT_MIN;\n int sum=0;\n for(int i=mid;i>=low;i--){\n sum=sum+nums[i];\n LSum=max(LSum,sum);\n }\n\n sum=0;\n for(int ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n array<int,4> solve(vector<int> &nums, int left, int right){ // left part, middle/better part, right part\n if(left > right) return {-10002, -10002, -10002, -10002};\n if(left == right){\n return {nums[left], nums[left], nums[left], nums[left]};\n ... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int crossMaxSubArray(vector<int>& nums, int left, int mid, int right) {\n int left_sum = INT_MIN, right_sum = INT_MIN, sum = 0;\n\n // Left of mid\n for (int i = mid; i >= left; i--) {\n sum += nums[i];\n left_sum = max(left_sum, sum... |
53 | <p>Given an integer array <code>nums</code>, find the <span data-keyword="subarray-nonempty">subarray</span> with the largest sum, and return <em>its sum</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]
<strong>Output:</strong> 6
<... | 3 | {
"code": "class Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n return maxSubArray(nums, 0, nums.size() - 1);\n }\n\n int maxSubArray(vector<int>& nums, int left, int right) {\n if (left > right) return INT_MIN;\n int mid = (left + right) / 2;\n int leftsum = 0, righ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 0 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n = s.size();\n int res = 0;\n for(char c = 'a'; c <= 'z'; ++c){\n //////////////////c = 'a'\n int l = 0;\n while(l < n && s[l] != c){\n ++l;\n }\... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 0 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n vector<int> letters(26,0);\n int result =0,len = s.length();\n char letter = 'a';\n for(int i = 0;i<26;i++){\n int start = 0, end = len-1;\n while(start < len-1){\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 0 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n=s.size(); int ans=0;\n vector<int>vmin(26,-1);\n vector<int>vmax(26,-1);\n for(int i=0; i<s.size(); i++){\n if(vmin[s[i]-'a']==-1) vmin[s[i]-'a']=i;\n vmax[s[i]-'a']=i;\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 0 | {
"code": "// class Solution {\n// public:\n// int countPalindromicSubsequence(string s) {\n\n// vector<int> vec = {};\n// int total = 0;\n\n// for(int i = 0; i<s.size(); i++) {\n// int start = 0;\n// int end = 0;\n \n// if(std::find(vec.begin... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 2 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n // in order to be unique, either the 1st or 2nd element needs to be different\n // find number of x-y pairs such that x appears again later\n // maintain a frequency to the left, and a frequency to the right?\... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 2 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n set<pair<char, char>> res;\n\n unordered_set<char> left;\n\n unordered_map<char, int> right;\n\n for (int i = 0; i < s.size(); i++) {\n right[s[i]]++;\n }\n\n for (int mid = 0; ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n void findCount(unordered_map<char, int> &indexMap, char ch, unordered_set<string> &st, unordered_map<char, int> &lastIndexMap) {\n int index = indexMap[ch];\n for (auto it : indexMap) {\n char tempCh = it.first;\n int lastIndex = lastIndexM... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n unordered_set<string> st;;\n unordered_map<char,int> mp;\n for(auto i:s)\n mp[i]++;\n\n vector<int> first(26,-1),last(26,-1);\n for(int i=0;i<s.size();i++)\n {\n if(first... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n unordered_map<int,int> left;\n unordered_map<int,int> right;\n left[s[0] - 'a']++;\n int n = s.size();\n int ans = 0;\n unordered_map<string,int> hash;\n for(int i=n-1;i>1;i--)\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n unordered_map<char, int> m1;\n unordered_map<char, pair<int, int>> m2;\n int n = s.length();\n vector<int> pre(n+1, 0);\n\n // Step 1: Populate m1 and m2\n for(int i = 0; i < n; i++) {\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n=s.size();\n vector<int> dp(n+1,1);\n set<string> s1;\n for(int i=0;i<26;i++)\n {\n string p;\n for(int j=0;j<26;j++)\n {\n p=p+char(97+i);\n... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n \n int n = s.size(), res = 0;\n vector<vector<int>> mp(26);\n\n for(int i = 0; i < n; i++)\n mp[s[i] - 'a'].push_back(i); \n \n for(int i = 0; i < 26; i++)\n {\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n = s.size();\n vector<vector<int>>arr(26);\n for(int i = 0;i<n;i++){\n arr[s[i]-'a'].push_back(i);\n }\n int ans = 0;\n for(int i = 0;i<26;i++){\n if(arr[i].size... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n vector<vector<int>> v(26);\n\n for (int i = 0; i < s.size(); i++) {\n int ch = s[i] - 'a';\n\n v[ch].push_back(i);\n }\n\n int count = 0;\n\n for (int i = 0; i < 26; i++) {\... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n vector<vector<int>> pos(26) ;\n for(int i=0;i<s.length();++i){\n pos[s[i]-'a'].push_back(i);\n }\n int res =0,i=0;\n for(int i=0;i<pos.size();i++){\n if(pos[i].size()==0) co... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n = s.length();\n int ans = 0;\n vector<vector<int>> chars(26, vector<int>());\n for(int i = 0; i < n; i++)\n {\n chars[s[i] - 'a'].push_back(i);\n }\n for(int i = 0;... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n map<string,int> mp;\n int n = s.size();\n int pre[n+1][26];\n memset(pre,0,sizeof pre);\n for(int i=0;i<n;i++){\n\n for(int j=0;j<26;j++)pre[i+1][j]=pre[i][j];\n pre[i+1][s[... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n\n unordered_map<char,vector<int>> ump;\n for(int i=0;i<s.length();i++)\n {\n ump[s[i]].push_back(i);\n }\n\n\n int ct =0;\n\n unordered_map<char,int> count;\n\n for(auto ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n=s.size();\n unordered_set<char>st(s.begin(),s.end());\n int ans=0;\n for(int i=0;i<n;i++){\n int idx=-1;\n if(st.find(s[i])!=st.end()){\n for(int j=i+1;j<n;j++... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int solve(int end , int st, string s){\n int i = st+1;\n int num = 0;\n vector<int> fre(26,0);\n while(i<end){\n fre[s[i]-'a']++;\n if(fre[s[i]-'a']>=2){\n num++;\n }\n i++;\n }\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n \n int countPalindromicSubsequence(string s) {\n \n int n=s.size();\n \n unordered_set<string>st;\n unordered_map<char,vector<int>>mp;\n for(int i=0;i<n;i++){\n mp[s[i]].push_back(i);\n }\n\n for(auto it:mp... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n map<char, vector<int>> pos;\n set<string> v;\n int ans = 0;\n\n for(int i = 0; i < s.size(); i++)\n {\n pos[s[i]].push_back(i);\n }\n\n for(auto it: pos)\n {\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n map<char, vector<int>> pos;\n set<string> v;\n int ans = 0;\n\n for(int i = 0; i < s.size(); i++)\n {\n pos[s[i]].push_back(i);\n }\n\n for(auto it: pos)\n {\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int unique(string s, int l, int r) {\n unordered_set<char> st;\n for (int i = l; i <= r; i++)\n st.insert(s[i]);\n return st.size() - 1;\n }\n int countPalindromicSubsequence(string s) {\n unordered_map<char, pair<int, int>> mp;\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int unique(string s, int l, int r) {\n unordered_set<char> st;\n for (int i = l; i <= r; i++)\n st.insert(s[i]);\n return st.size() - 1;\n }\n int countPalindromicSubsequence(string s) {\n unordered_map<char, pair<int, int>> mp;\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n map <char,vector <int> > mp;\n for (int i=0;i<s.size();i++){\n mp[s[i]].push_back(i);\n } \n int sum=0;\n for (auto it:mp){\n vector <int > v=it.second;\n if (v.size()>=2){\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int unique(string s,int l,int r){\n unordered_set<char>st;\n for(int i=l;i<=r;i++)\n st.insert(s[i]);\n return st.size()-1;\n }\n int countPalindromicSubsequence(string s) {\n unordered_map<char,pair<int,int>>mp;\n int n = s.len... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\nprivate:\n int unique(string s,int start,int end){\n vector<int> seen(26,0);\n for(int i=start+1;i<end;i++){\n seen[s[i]-'a']=1;\n }\n return accumulate(seen.begin(),seen.end(),0);\n }\npublic:\n int countPalindromicSubsequence(string s) {\n... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "#include<bits/stdc++.h>\n\nstruct node{\n bitset<26>bit;\n \n node() {\n bit = bitset<26>(0);\n };\n \n void set(int i){\n bit.set(i);\n }\n \n int cnt(){\n return bit.count();\n }\n \n void merge(node &l, node &r){\n bit = (l.bit | r.bit);\n... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "int firstOccurence(string s , char c){\n int n = s.length();\n for(int i = 0 ; i < n ; i++)\n if(s[i] == c)\n return i;\n \n return -1;\n}\n\nint lastOccurence(string s , char c){\n int n = s.length();\n for(int i = n-1 ; i >= 0 ; i--)\n if(s[i] == c)\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n = s.size();\n vector<int> first(26, -1), last(26, -1);\n unordered_map<char, set<int>> mp;\n for(int i = 0; i < n; i++) {\n char c = s[i];\n if(first[c-'a'] == -1) {\n ... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int n = s.size();\n unordered_map<char,pair<int,int>> mp;\n vector<vector<int>> unique(26,vector<int>(n,0));\n int ans =0;\n\n for(int i=0;i<n;i++){\n char ch = s[i];\n if(m... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int len = s.size();\n if (len < 3) {\n return 0;\n }\n map<char, int> freq_map;\n map<char, vector<int>> pos_map;\n for (int i = 0; i < len; i++) {\n if (freq_map.fin... |
2,059 | <p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>
<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>
<p>A <stro... | 3 | {
"code": "class Solution {\npublic:\n int countPalindromicSubsequence(string s) {\n int len = s.size();\n if (len < 3) {\n return 0;\n }\n map<char, int> freq_map;\n map<char, vector<int>> pos_map;\n for (int i = 0; i < len; i++) {\n if (freq_map.fin... |
1,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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,116 | <p>Given the <code>root</code> of a binary tree, the level of its root is <code>1</code>, the level of its children is <code>2</code>, and so on.</p>
<p>Return the <strong>smallest</strong> level <code>x</code> such that the sum of all the values of nodes at level <code>x</code> is <strong>maximal</strong>.</p>
<p>&n... | 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.