id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n void findindex(string s,string a,vector<int> &x){\n auto pos=s.find(a,0);\n if (pos==string::npos)return;\n while(pos!=string::npos){\n x.push_back(pos);\n pos=s.find(a,pos+1);\n }\n return;\n }\n vector<int> beau...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "// https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-i/?envType=problem-list-v2&envId=string-matching\nclass Solution {\npublic:\n\n vector<int> rabinKarp(string txt, string pat)\n {\n int m=pat.size(),n=txt.size();\n vector<int> indices;\n if(m>n)\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n // get queue of Is\n // get queue of Js\n // for each I, pop frontmost J until j >= i - k\n queue<int> Is = getIndices(s, a);\n queue<int> Js = getIndices(s, b);\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n void computeLPS(string pattern, vector<int>& lps) {\n int M = pattern.length();\n int len = 0; // Length of the previous longest prefix & suffix\n\n lps[0] = 0; // Because there is no proper suffix and prefix of pattern[0..0]\n\n int i = 1;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int>solve(string target,string s){\n int n=target.size();\n vector<int>ans;\n int m=s.size();\n for(int i=0;i<n-m+1;i++){\n if(target.substr(i,m)==s) ans.push_back(i);\n } \n return ans;\n }\n vector<int> beau...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n inline int abs(int a) {\n return a > 0 ? a : -a;\n }\n\n void getAppearances(string s, string a, vector<int>& appearances) {\n int n = a.length();\n \n if (s.length() < n) {\n return;\n }\n for (int i = 0; i <= s.leng...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n = s.size();\n vector<int>ans;\n unordered_map<int,int> m;\n vector<int> v;\n vector<int> d(n,0);\n int ind;\n for(int i = 0; i < n; i++){\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n bool has_prefix(const string &s, const string &prefix, const int offset)\n {\n for (int i = 0; i < prefix.length(); ++i)\n {\n if (offset + i >= s.length() || s[offset + i] != prefix[i])\n {\n return false;\n }\...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n=s.length(),al=a.length(),bl=b.length();vector<int> aind;\n vector<int> v(n,0);\n int na=-1,nb=-1;\n int i=0,j=0,c=0;vector<int> ans;\n string as,bs;\n for(int...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n\n vector<int> find(string& s, string &delim) {\n vector<int> indexes;\n for(int i = 0; i < s.size(); i++) {\n string token = s.substr(i, delim.size());\n\n if(token == delim) {\n indexes.push_back(i);\n }\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n\n // Fills lps[] for given pattern pat\n void computeLPSArray(string& pat, int M, vector<int>& lps)\n {\n int len = 0;\n lps[0] = 0;\n int i = 1;\n while (i < M) {\n if (pat[i] == pat[len]) {\n len++;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n bool check(string& s,string& a,int idx){\n for(int i=idx;i<a.length()+idx;i++){\n if(s[i]!=a[i-idx]) return 0;\n }\n return 1;\n }\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n if((int)a.length()>(int)s.le...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\nvector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> ans;\n\n int ls = s.length();\n int la = a.length();\n int lb = b.length();\n vector<int> a_idx;\n vector<int> b_idx;\n\n for(int i = 0 ; i <= ls-la ; i++){\n string sub ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n\n vector<int> returnPos(string s, string a) {\n string new_str = a+\"#\"+s;\n vector<int> res;\n int lps[new_str.length()];\n lps[0] = 0;\n for(int i=1;i<new_str.length();i++) {\n int k = lps[i-1];\n\n while(k > 0 && ne...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n\n vector<int> returnPos(string s, string a) {\n string new_str = a+\"#\"+s;\n vector<int> res;\n int lps[new_str.length()];\n lps[0] = 0;\n for(int i=1;i<new_str.length();i++) {\n int k = lps[i-1];\n\n while(k > 0 && ne...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> ans;\n int n=s.length();\n if(n<a.length()||n<b.length())\n return ans;\n vector<int> a1, b1;\n for(int i=0; i<=n - a.length(); i++){\n i...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n set<int> output;\n string sA = \"\";\n string sB = \"\";\n queue<int> a_queue;\n queue<int> b_queue;\n for (int i = 0; i < s.size(); ++i)\n {\n\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int>as;\n vector<int>bs;\n\n int m=a.size();\n int n=b.size();\n\n int i=0;\n while(i<s.size())\n {\n string curr=s.substr(i,m);\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n\n vector<int> returnPos(string s, string a) {\n string new_str = a+\"#\"+s;\n vector<int> res;\n int lps[new_str.length()];\n lps[0] = 0;\n for(int i=1;i<new_str.length();i++) {\n int k = lps[i-1];\n\n while(k > 0 && ne...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n=s.size();\n int s1=a.size();\n int s2=b.size();\n vector<int> ans;\n vector<int> a1,a2;\n\n for(int i=0;i<n;i++)\n {\n if(s[i]==a[0])\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n\n vector<int> ans;\n\n int n=s.size();\n\n vector<int> pos1;\n vector<int> pos2;\n\n helper(s,n,pos1,a);\n helper(s,n,pos2,b);\n\n vector<int> checker(n+1,0)...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\n vector<long long> p_pow;\n long long hash(string const& s){\n const int m = 1e9 + 9;\n long long hash_value = 0;\n for (int i = 0; i < (int)s.size(); i++) {\n hash_value = (hash_value + (s[i] - 'a' + 1) * p_pow[i]) % m;\n }\n return has...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n \n void kmp(string s,vector<int>&lps)\n {\n int n=s.size();\n\n for(int i=1,j=0;i<n;)\n {\n if(s[i]==s[j])\n {\n lps[i]=j+1;\n i++;\n j++;\n }\n else\n {\n if(j==0)\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n void compute(string pat,vector<int>&lps,int m)\n {\n lps[0]=0;\n int len=0;\n int i=1;\n while(i<m)\n {\n if(pat[i]==pat[len]){\n len++;\n lps[i]=len;\n i++;\n }\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n void computeLPS(string pattern, vector<int>& lps) {\n int M = pattern.length();\n int len = 0; // Length of the previous longest prefix & suffix\n\n lps[0] = 0; // Because there is no proper suffix and prefix of pattern[0..0]\n\n int i = 1;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\nvector<int> rec(string str, string s)\n{ \n vector<int> v;\n size_t pos = str.find(s, 0);\n\n if (pos == string::npos)\n return v;\n\n while (pos != string::npos) {\n v.push_back(pos);\n pos = str.find(s, pos + 1);\n }\n return v;\n}\n v...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\n vector<int> lps(string s1)\n {\n vector<int> v(s1.length(),0);\n int i = 0;\n int j = 1;\n while(j < s1.length())\n {\n if(s1[i] == s1[j])\n {\n v[j] = i+1;\n i++;\n j++;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "#define MOD 1000000007\n#define PRIME 100003\n\nvector<int> power;\nint add(int x, int y) {\n int temp = x + y;\n return temp >= MOD ? temp - MOD : temp;\n}\n\nint sub(int x, int y) {\n int temp = x - y;\n return temp < 0 ? temp + MOD : temp ;\n}\n\nint mult(int x, int y) {\n long long int t...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> func(string &s, string &a) {\n int size = a.size();\n a.push_back('#');\n a.insert(a.end(), s.begin(), s.end());\n vector<int>ans(a.size(), 0);\n vector<int>actual;\n for(int i = 1; i < a.size(); ++i) {\n int te...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n // void kmp(string &s, string &c, vector<int> &lps){\n // cout<<lps[0]<<\" \";\n // for(int i=1; i<lps.size(); i++){\n // int pind = lps[i-1];\n // while(pind > 0 && pind < c.size() && s[i] != c[pind])\n // pind = lps[pind-1]...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> kmp(string &s){\n int n=s.size();\n vector<int> lcs(n,0);\n for(int i=1; i<n; i++){\n int prev=lcs[i-1];\n while(prev>0 && (s[i]!=s[prev])){\n prev=lcs[prev-1];\n }\n lcs[i]=prev+(s[i]...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> CalcZ(const string &s)\n {\n int n=s.size();\n vector<int> z(n,0);\n for(int i=1,l=0,r=0;i<n;++i)\n {\n if(i<=r && z[i-l]<r-i+1)\n {\n z[i]=z[i-l];\n }\n else\n {\...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> getIndices(string &s, string &pattern) {\n string combo = pattern + '#' + s;\n int n = combo.length();\n vector<int> lps(n, 0), res;\n\n for (int i=1, j=0; i<n; i++) {\n while (j>0 and combo[i] != combo[j]) j = lps[j-1];\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> getIndices(string &s, string &pattern) {\n string combo = pattern + '#' + s;\n int n = combo.length();\n vector<int> lps(n, 0), res;\n\n for (int i=1, j=0; i<n; i++) {\n while (j>0 and combo[i] != combo[j]) j = lps[j-1];\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\n vector<int> kmp(string s){\n vector<int> ans(s.size(), 0);\n for(int i=1;i<s.size();i++){\n int prev = ans[i-1];\n while(prev > 0 && s[i] != s[prev]) prev = ans[prev - 1];\n ans[i] = prev + (s[i] == s[prev] ? 1 : 0);\n }\n r...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int>kmp(string s)\n {\n vector<int>lps(s.size(),0);\n for(int i=1;i<s.size();i++)\n {\n int __prev_match=lps[i-1];\n while(__prev_match>0 && s[__prev_match]!=s[i])\n {\n __prev_match=lps[__prev_mat...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> KMP(string s)\n {\n vector<int> LPS(s.size(),0);\n for(int i=1;i<s.size();i++)\n {\n int prev_idx = LPS[i-1];\n while(prev_idx>0&&s[i]!=s[prev_idx])\n {\n prev_idx = LPS[prev_idx-1];\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\n vector<int>kmp(string a,string b){\n string t=a+'#'+b;\n int n=t.size();\n vector<int>lps(n+1,-1);\n int i=0,j=-1;\n while(i<n){\n while(j!=-1 && t[i]!=t[j]){\n j=lps[j];\n }\n lps[++i]=++j;\n }\...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> kmp(string s, string t) {\n vector<int>ans;\n int m=t.size();\n s=t+'#'+s;\n int n=s.size();\n vector<int>lsp(n,0);\n for(int i=1;i<n;i++){\n int pre_ind=lsp[i-1];\n while(pre_ind>0 && s[i]!=s[pre_ind]...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> z_index(string s, int m) {\n int n = s.size();\n vector<int> z(n, 0);\n int l = 0, r = 0;\n for (int i = 1; i < n; i++) {\n if (i < r) {\n z[i] = min(r - i, z[i - l]);\n }\n while (i + z[i...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n std::vector<int> beautifulIndices(const std::string& s, const std::string& a, const std::string& b, const int& k) {\n const size_t len_s = s.size(), len_a = a.size(), len_b = b.size();\n std::vector<int> indices;\n\n if(len_a > len_s || len_b > len_s) {\n return i...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n std::vector<int> beautifulIndices(const std::string& s, const std::string& a, const std::string& b, const int& k) {\n const size_t len_s = s.size(), len_a = a.size(), len_b = b.size();\n std::vector<int> indices;\n\n if(len_a > len_s || len_b > len_s) {\n return i...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\n void fillps(string s, vector<int>& lps) {\n lps[0] = 0;\n int len = 0, i = 1;\n while (i < s.size()) {\n if (s[len] == s[i]) {\n len++;\n lps[i] = len;\n i++;\n } else {\n if (len ==...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\n void fillps(string s, vector<int>& lps) {\n lps[0] = 0;\n int len = 0, i = 1;\n while (i < s.size()) {\n if (s[len] == s[i]) {\n len++;\n lps[i] = len;\n i++;\n } else {\n if (len ==...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\nvector<int>calc(int &n , string &y){\n vector<int>x(n);\n int l=0,r=0;\n for(int i=1;i<n;i++){\n if(i>r){\n l=i,r=i;\n while(r<n && y[r]==y[r-l])r++;\n r--;\n x[i]=r-l+1;\n }\n else{\n if(r-i+1>x...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "#define ll long long int\n#define vob vector<bool>\n#define voi vector<int>\n#define voll vector<ll>\n#define vvoi vector<voi>\n#define vvoll vector<voll>\n#define pq priority_queue\n#define umap unordered_map\n#define pii pair<int,int>\n#define vpii vector<pii>\n#define avg(a,b) (a+b)/2\n#define forn(i,n)...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n\n vector<int> kmp(string s1, string s2){\n string s = s2 + \"#\" + s1;\n int m = s2.size();\n int n = s.size();\n vector<int> pi(n, 0);\n vector<int> res;\n\n for(int i=1; i<n; i++){\n int l = pi[i-1];\n while(l>...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n set<int> a_indices;\n set<int> b_indices;\n\n int slen = s.length();\n int alen = a.length();\n int blen = b.length();\n\n for (int i = 0; i <= slen - alen; i++) {\...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\nprivate:\n vector<int> kmp(string text,string pattern){\n \n string s = pattern + \"#\" + text;\n\n vector<int> lps(s.size(),0);\n int length = 0;\n \n //i = 1 is very imp , 0 mat likh dena , kyuki lps[0] should be zero\n int i=1;\n while(i<s.size()){\n if(s[i] == s...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\nvector<int> prefix_function(string s) {\n int n = (int)s.length();\n vector<int> pi(n);\n for (int i = 1; i < n; i++) {\n int j = pi[i-1];\n while (j > 0 && s[i] != s[j])\n j = pi[j-1];\n if (s[i] == s[j])\n j++;\n pi[i] ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
3
{ "code": "class Solution {\npublic:\n void KMP(string &s, string &a, vector<int>& va) {\n string t = a + \"@\" + s;\n vector<int> lps(1,0);\n for(int i=1;i<t.size();++i) {\n int cur = lps[i-1];\n \n while(cur > 0 && t[cur] != t[i]) {\n cur = lps...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
0
{ "code": "typedef long long int ll;\nclass Solution {\npublic:\n ll countBitsTillN(ll N,ll bitPow){\n ll blockSize = bitPow+bitPow;\n ll fullBlocks = (N+1) / blockSize;\n ll count = fullBlocks*1LL*bitPow;\n ll remainder = (N+1) % blockSize;\n count+=max(0LL,remainder - bitPow);\...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
0
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n /*\n 7654 3210\n 0000 0000\n 0000 0001\n 0000 0010\n 0000 0011\n 0000 0100\n 0000 0101\n 0000 0110\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
0
{ "code": "class Solution {\npublic:\n long long accumulated(long long num, int &x) {\n long long ans = 0;\n for(long long i = x-1, j; 1 <= (num>>i); i += x) {\n j = ((long long)1<<i);\n ans += (num / (j*2)) * j + max((long long)0, num % (j*2) - j + 1);\n }\n retur...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
1
{ "code": "#define ll long long\nclass Solution \n{\npublic:\n ll findMaximumNumber(ll k, int x) \n {\n ll left = 1, right = 1e15;\n while (left <= right)\n {\n ll mid = (left+right)/2;\n if (solve(mid, x) <= k) left = mid+1;\n else right = mid-1;\n }...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "#define ll long long\nclass Solution \n{\npublic:\n ll findMaximumNumber(ll k, int x) \n {\n ios::sync_with_stdio(false); cin.tie(0);\n \n ll left = 1, right = 1e15;\n while (left <= right)\n {\n ll mid = (left+right)/2;\n if (solve(mid, x) <= ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "#define ll long long\nclass Solution \n{\npublic:\n ll findMaximumNumber(ll k, int x) \n {\n ios::sync_with_stdio(false); cin.tie(0);\n \n ll left = 1, right = 1e15;\n while (left <= right)\n {\n ll mid = (left+right)/2;\n if (solve(mid, x) <= ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "#include <cmath>\nclass Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n long long left_num = 0;\n long long right_num = 1e15;\n while (left_num <= right_num){\n long long middle_num = (right_num-left_num)/2 + left_num;\n long long midd...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n long long ans;\n long long l = 0, r = 1e17;\n vector<int> v; //bits which should be considered\n for (int i = 0; i < 54;i++){\n if(((i+1)%x)==0)\n v.push_back(i);\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n long long ans;\n long long l = 0, r = 1e17;\n vector<int> v; //bits which should be considered\n for (int i = 0; i < 54;i++){\n if(((i+1)%x)==0)\n v.push_back(i);\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n vector<long long> masks;\n for(int i=x-1;i<50;i+=x){\n masks.push_back(1LL<<i);\n }\n int num=0;\n long long s=0, e=LONG_LONG_MAX/10000, ret=0;\n while(s<=e){\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n vector<long long> masks;\n for(int i=x-1;i<50;i+=x){\n masks.push_back(1LL<<i);\n }\n int num=0;\n long long s=0, e=1000000000000000, ret=0;\n while(s<=e){\n lo...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n vector<long long> masks;\n for(int i=x-1;i<50;i+=x){\n masks.push_back(1LL<<i);\n }\n int num=0;\n long long s=0, e=LONG_LONG_MAX/10000, ret=0;\n while(s<e){\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
2
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n vector<long long> masks;\n for(int i=x-1;i<50;i+=x){\n masks.push_back(1LL<<i);\n }\n int num=0;\n long long s=1, e=1e15, ret=0;\n while(s<=e){\n long long acc=...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n vector<long long> masks;\n for(int i=x-1;i<50;i+=x){\n masks.push_back(1LL<<i);\n }\n int num=0;\n long long s=0, e=1000000000000000, ret=0;\n while(s<=e){\n lo...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n vector<long long> masks;\n for(int i=x-1;i<50;i+=x){\n masks.push_back(1LL<<i);\n }\n int num=0;\n long long s=0, e=1e15, ret=0;\n while(s<=e){\n long long acc=...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) {\n long long int num = 0, cnt = 0, total = 0;\n long long int po[54];\n po[0] = 1;\n for (int i = 1; i < 54; i++) {\n po[i] = po[i - 1] + po[i - 1];\n }\n for (int i = 53; i ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long count(long long num, int x){\n if(num==1){\n if(x==1) return (long long)1; \n else return (long long)0;\n }\n\n if(num==2){\n if(x==1) return 2ll;\n if(x==2) return 1ll;\n }\n // cout<<nu...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n vector<long long> v;\n void solve(long long x) {\n if (x == 0) {\n return;\n }\n if (x == 1) {\n v[0]++;\n return;\n }\n if (x == 2) {\n v[0]++;\n v[1]++;\n return;\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic: \n vector<long long>bitCount ;\n void getBits(long long num ) { \n if(num == 0) return ;\n if(num == 1) {\n bitCount[0] += 1;\n return ;\n }\n if(num == 2) \n { \n bitCount[0]+=1;\n bitCount[1] +...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic: \n vector<long long>bitCount ;\n void getBits(long long num ) { \n if(num == 0) return ;\n if(num == 1) {\n bitCount[0] += 1;\n return ;\n }\n if(num == 2) \n { \n bitCount[0]+=1;\n bitCount[1] +...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long K, int x) {\n const int MAXP = 60;\n typedef pair<__int128, __int128> pll;\n pll f[MAXP + 5][2];\n\n function<pll(int, int, long long)> dp = [&](int pos, int full, long long n) {\n if (pos < 0) retur...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long findMaximumNumber(long long k, int x) { // 累加<=k\n // 二分 + 数位dp\n long long lo = 1, hi = (k + 1) << x;\n long long ans = 1;\n while (lo <= hi) {\n long long md = lo + ((hi - lo) >> 1);\n // 求解出1~md的数字的总价值\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n long long dp[65][2][65];\n long long k1;\n int x1;\n long long digitdp(string &s,int pos, bool tight,int count) {\n if (pos==0) return count;\n if (dp[pos][tight][count]!=-1) return dp[pos][tight][count];\n int ub = tight ? s[s.size()-pos]- '0' :...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n ll dp[65][2][65];\n ll k1,x1;\n ll f(string& s,ll pos,bool tight,ll cnt){\n if(pos==0)return cnt;\n if(dp[pos][tight][cnt]!=-1)return dp[pos][tight][cnt];\n ll ub = tight?s[s.size()-pos]-'0':1;\n\n ll ans =0;\n fo...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n bool helper(long num, long k, int x){\n int len = log2(num);\n long tot_prices = 0;\n vector<long> bitSum(len + 1);\n while(num > 0){\n int MSB = log2(num);\n long tmp = (long)1 << MSB;\n bitSum[MSB] += num - tmp + ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n bool helper(long num, long k, int x){\n int len = log2(num);\n long tot_prices = 0;\n vector<long> bitSum(len + 1);\n while(num > 0){\n int MSB = log2(num);\n long tmp = (long)1 << MSB;\n bitSum[MSB] += num - tmp + ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n bool helper(long num, long k, int x){\n int len = log2(num);\n long tot_prices = 0;\n vector<long> bitSum(len + 1);\n while(num > 0){\n int MSB = log2(num);\n long tmp = (long)1 << MSB;\n bitSum[MSB] += num - tmp + ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "using LL = long long;\n\nclass Solution {\n vector<vector<LL>> memo;\npublic:\n long long findMaximumNumber(long long k, int x) {\n LL left = 0, right = (k+1)<<x;\n\n while(left<=right){\n LL mid = left+((right-left)>>1);\n int m = __lg(mid)+1;\n memo.as...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "using LL = long long;\n\nclass Solution {\n vector<vector<LL>> memo;\npublic:\n long long findMaximumNumber(long long k, int x) {\n LL left = 0, right = (k+1)<<x;\n\n while(left<=right){\n LL mid = left+((right-left)>>1);\n int m = __lg(mid)+1;\n memo.as...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\n # define ll long long\n bool isPossible(ll num, ll k, int x)\n {\n ll cnt = 0;\n int len = log2(num);\n vector<ll> cntSetBits(len+1);\n while(num){\n int MSB = log2(num);\n ll temp = (1LL << MSB);\n cntSetBits[MSB] += ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n void calc(long long n, vector<long long > &arr){\n if( n <= 0) return; \n if(n == 1) {\n arr[0]++;\n return;\n }\n if(n == 2){\n arr[0]++;\n arr[1]++;\n return;\n }\n int msb = lo...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\n bool helper(long num, long k, int x){\n long sum=0;\n vector<long> bitSum(61);\n while(num > 0){\n int MSB = log2(num);\n long p = (long)1 << MSB;\n bitSum[MSB] += num - p + 1;\n for(int i = 0 ; i < MSB ; i++)\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\n bool helper(long num, long k, int x){\n long long sum=0;\n vector<long> bitSum(61);\n for(int i=60;i>=0;i--){\n long long p=1LL<<i;\n if((p & num)==0)continue;\n //cout<<p<<\" \";\n bitSum[i]+=num-p+1;\n for(...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n void setBits(vector<ll> &bits, ll n) {\n if (n == 0) {\n return;\n }\n \n int bitLen = (int)log2(n) + 1;\n ll x = (1LL << (bitLen - 1)); // Ensure safe shifting with 1LL\n \n bits[64 - bitLen] ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long helper(ll num, int x) {\n ll res = 0;\n vector<ll> vec(63, 0);\n for(int i = 0; i < 63; i++) {\n ll idx = (num - ((ll)1<<i));\n if(idx < 0)\n continue;\n ll rsvd = idx % (((ll...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n vector<ll> bit_count;\n void helper(ll num)\n {\n if(num<1)\n {\n return;\n }\n //no of bits needed to represent a number.\n int bit_length=log2(num)+1;\n ll closest_power_of_two=(1ll<<(bit_...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n vector<ll> bits;\n void getBitsCount(ll num) {\n // Base case\n if(num == 0) return ;\n if(num == 1) {\n bits[0] += 1;\n return ;\n }\n\n // Find nearest power of 2 smaller than num;\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<ll>bitCount;\n void findSetCount(ll num){\n if(num==0){\n return ;\n }\n if(num==1){\n //01\n bitCount[0]+=1;\n return ;\n }\n\n if(num==2){\n //00 01 1...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "// Approach-2\n// T.C : O(log(k) * log(num)) - Accepted\n// S.C : O(1)\nclass Solution {\npublic:\n typedef long long ll;\n vector<ll> bitCount;\n\n void getBits(ll number) {\n if (number == 0)\n return;\n\n if (number == 1) {\n bitCount[0]++;\n retur...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n vector<ll> bitcount;\n void getbits(ll num){\n if(num == 0) return ;//000\n if(num == 1){//bitcount of 000 + 001\n bitcount[0]++;\n return ;\n }\n if(num == 2){//bitcount 000+001+010\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "#define ll long long\nclass Solution \n{\npublic:\n void sol(vector<ll>&v,ll mid)\n {\n if(mid==0)\n {\n return;\n }\n int k=-1;\n for(int i=0;i<64;i++)\n {\n if(mid & ((ll)1<<i))\n {\n k=i;\n }\n ...
3,240
<p>You are given an integer <code>k</code> and an integer <code>x</code>. The price of a number&nbsp;<code>num</code> is calculated by the count of <span data-keyword="set-bit">set bits</span> at positions <code>x</code>, <code>2x</code>, <code>3x</code>, etc., in its binary representation, starting from the least sign...
3
{ "code": "#define ll long long\nclass Solution \n{\npublic:\n void sol(vector<ll>&v,ll mid)\n {\n if(mid==0)\n {\n return;\n }\n int k=-1;\n for(int i=0;i<64;i++)\n {\n if(mid & ((ll)1<<i))\n {\n k=i;\n }\n ...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "/*\nfind all the indices\n*/\n\ninline constexpr int MAX_N = 5e5 + 5;\ninline constinit int lps[MAX_N]{}, am[MAX_N]{}, bm[MAX_N]{};\n\ninline int findMatches(auto &&s, auto &&p, int *matches) {\n int n = s.size(), m = p.size();\n lps[0] = 0;\n for (int i = 1, j = 0; i < m; ++i) {\n while (j...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "/*\nfind all the indices\n*/\n\ninline constexpr int MAX_N = 5e5 + 5;\ninline constinit int lps[MAX_N]{}, am[MAX_N]{}, bm[MAX_N]{};\n\ninline int findMatches(auto &&s, auto &&p, int *matches) {\n int n = s.size(), m = p.size();\n lps[0] = 0;\n for (int i = 1, j = 0; i < m; ++i) {\n while (j...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "#include <iostream>\n#include <vector>\n#include <string>\n#include <algorithm>\n\nclass Solution {\npublic:\n const int prime = 31;\n const int mod = 1e9 + 7;\n\n void get(const std::string& input, const std::string& pattern, std::vector<int>& arr) {\n int n = input.size();\n int a ...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> v;\n if (s.length() < a.length() || s.length() < b.length()) return v;\n long long int hasha = 0, hashb = 0;\n long long int mod = 1000000007;\n long long int ...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "int _ = [](){ios_base::sync_with_stdio(false);cin.tie(nullptr);return 0;}();\n\nvector<int> findAllSubstrings(const string& s, const string& a)\n{\n vector<int> continuations{};\n continuations.reserve(a.size());\n\n int j = 0;\n for (int i = 1; i < a.size(); ++i)\n {\n if (a[i] == a[...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "#include <execution>\nint _ = [](){ios_base::sync_with_stdio(false);cin.tie(nullptr);return 0;}();\n\nvector<int> findAllSubstrings(const string& s, const string& a)\n{\n vector<int> continuations{};\n continuations.reserve(a.size());\n\n int j = 0;\n for (int i = 1; i < a.size(); ++i)\n {\n...
3,303
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "#pragma GCC optimize(\"O3\")\n#include <execution>\nint _ = [](){ios_base::sync_with_stdio(false);cin.tie(nullptr);return 0;}();\n\nvector<int> findAllSubstrings(const string& s, const string& a)\n{\n vector<int> continuations{};\n continuations.reserve(a.size());\n\n int j = 0;\n for (int i = ...