id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
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 <= i <= 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 int i=0,j=0;\n vector<int>tmp,tmp2;\n set<char>st(a.begin(),a.end()),st2(b.begin(),b.end());\n if(st.size()==1){\n while(i<s.length()){\n if(s[i]==a[j]){\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n\n void computeLPSArray(string &pat, int M, int *lps)\n\t{\n\t\tint len = 0;\n\t\tlps[0] = 0;\n\t\tint i = 1;\n\n\t\twhile (i < M)\n\t\t{\n\t\t\tif (pat[i] == pat[len])\n\t\t\t{\n\t\t\t\tlen++;\n\t\t\t\tlps[i] = len;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (len... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n void computeLPSArray(string &pat, int M, int *lps) {\n int len = 0;\n lps[0] = 0;\n int i = 1;\n\n while(i < M) {\n if(pat[i] == pat[len]) {\n len++;\n lps[i] = len;\n 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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n void computeLPSArray(string &pat, int M, int *lps) {\n int len = 0;\n lps[0] = 0;\n int i = 1;\n\n while(i < M) {\n if(pat[i] == pat[len]) {\n len++;\n lps[i] = len;\n 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 <= i <= 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 int ls = s.size();\n int la = a.size();\n int lb = b.size();\n\n queue<int> q;\n\n vector<int> last(lb, -1);\n vector<int> temp(26, -1);\n for (int i=0; i<lb... |
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 <= i <= 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 int ls = s.size();\n int la = a.size();\n int lb = b.size();\n\n queue<int> q;\n\n vector<int> last(lb, -1);\n vector<int> temp(26, -1);\n for (int i=0; i<lb... |
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 <= i <= 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 int n = s.length(), an = a.length(), bn = b.length(), base = 1e6 + 1, mod = 1e9 + 7, ap = 1, bp = 1, ah = 0, bh = 0;\n if (n < an || n < bn) {\n return {};\n }\n vecto... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n vector<int> computePrefixArray(string s) {\n int l = s.size();\n vector<int> prefix(l, 0);\n int i =1;\n int len = 0;\n\n while (i < l) {\n if (s[i] == s[len]) {\n len++;\n prefix[i] = len;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n vector<int> calcLps(string& pattern){\n vector<int> lps(pattern.size());\n lps[0]=0;\n int len=0;\n int i=1;\n while(i<pattern.size()){\n if(pattern[i]==pattern[len]){\n len++;\n lps[i]=len;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n \n void computeLps(const string& pat, vector<int>& LPS) {\n int M = pat.length();\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 LPS[i] = len;\n i++;\n } else ... |
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 <= i <= 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 std::vector<int> buff;\n\n auto preProcess = [&](std::string& P) {\n buff.resize(P.length() + 1, 0);\n buff[0] = -1;\n int i = 0, j = -1;\n int m = ... |
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 <= i <= 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 std::vector<int> buff;\n\n auto preProcess = [&](std::string& P) {\n buff.resize(P.length() + 1, 0);\n buff[0] = -1;\n int i = 0, j = -1;\n int m = ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\n\n vector<int> prefix_function(const string &s) {\n const int n = s.size();\n vector<int> pi(n);\n int l = 0;\n for (int i = 1; i < n; ++i) {\n while (l and s[i] != s[l])\n l = pi[l - 1];\n if (s[l] == s[i])\n ++l;\n pi[i] = l;\n }\n return ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\n\n vector<int> prefix_function(const string &s) {\n const int n = s.size();\n vector<int> pi(n);\n int l = 0;\n for (int i = 1; i < n; ++i) {\n while (l and s[i] != s[l])\n l = pi[l - 1];\n if (s[l] == s[i])\n ++l;\n pi[i] = l;\n }\n return ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 0 | {
"code": "class Solution {\npublic:\n vector<int> rabinkarp(string source, string target){\n int BASE=1e9+9;\n vector<int>res;\n int m = target.size();\n long long power = 1;\n for(int i = 0;i<m;i++){\n power = (power*31)%BASE;\n }\n long long targetCode... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "// https://leetcode.com/problems/find-beautiful-indices-in-the-given-array-ii/?envType=problem-list-v2&envId=string-matching\nclass Solution {\npublic:\n // Fills lps[] for given pattern pat\nvoid computeLPSArray(string& pat, int M, vector<int>& lps)\n{\n // Length of the previous longest prefix suff... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n \n void computeLPSArray(const string& pattern, vector<int>& lps) {\n int pref = 0; // length of the previous longest prefix suffix\n int suff = 1; // current position in the pattern\n lps[0] = 0; // lps[0] is always 0\n\n while (suff < pattern.size()) {\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n //longest palindromic proper prefix which is also a suffix\n vector<int>lps(string s){\n int n=s.size();\n vector<int>lps(n,0);\n for(int i=1;i<n;i++){\n int l=lps[i-1];\n while(l>0 && s[i]!=s[l]){\n l=lps[l-1];\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n \n vector<int> lp(string s){\n int n=s.size();\n vector<int>lps(n,0);\n int l=-1;\n int r=1;\n lps[0]=-1;\n\n while(r<n){\n bool flag=true;\n while(s[l+1]!=s[r]){\n if(l==-1){\n lps[r]=l;... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);\nvector<int> get_matches(string &s_, string &p) { //O(s.length+p.length)\n string s=p+\"#\"+s_;\n int n=s.length();\n int kmp[n+1];\n int i=0,j=-1; kmp[0]=-1;\n while (i<n) {\n while (j!=-1 && s[i]!=s[j]) j=kmp[j];\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "vector<int> get_matches(string &s_, string &p) { //O(s.length+p.length)\n string s=p+\"#\"+s_;\n int n=s.length();\n int kmp[n+1];\n int i=0,j=-1; kmp[0]=-1;\n while (i<n) {\n while (j!=-1 && s[i]!=s[j]) j=kmp[j];\n j++;i++;\n kmp[i]=j;\n }\n vector<int> matches;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "using ll = long long;\nclass Solution {\npublic:\n\n static const int MOD = 1e9 + 7;\n static const int base = 23;\n static const int mn = 1000000 + 10;\n ll hash[mn];\n ll power[mn];\n\n ll getHash(int u, int v) {\n\treturn (hash[v] - (hash[u - 1] * power[v - u + 1]) % MOD + MOD) % MOD;\... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"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,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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n std::vector<int> knuth_morris_pratt(std::string strText, std::string strPattern)\n {\n std::vector<int> vecResult;\n std::vector<int> vecLPS(strPattern.size());\n vecLPS[0] = 0;\n int iLen = 0;\n int iIdx = 1;\n\n // Calculating LP... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\n vector<int> lpsi(string &word) {\n int n = word.length();\n vector<int> lps(n);\n lps[0] = 0;\n int i = 1, len = 0;\n while (i < n) {\n if (word[len] == word[i]) {\n len++;\n lps[i] = len;\n i++... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n vector<int> make_lps(string &pat){\n int n = pat.size();\n vector<int> lps(n,0);\n \n for(int i=1;i<n;i++){\n int j = lps[i-1];\n \n while(j > 0 && pat[i] != pat[j]){\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n void f(vector<int>&lps , string v){\n int prefix =0 ;\n int suffix =1;\n \n while(suffix < v.length()){\n if(v[prefix] == v[suffix]){\n lps[suffix] = prefix+1;\n prefix++;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"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,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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 1 | {
"code": "class Solution {\npublic:\n void computeLPS(string pattern, vector<int>& lps) {\n int M = pattern.length();\n int len = 0; \n\n lps[0] = 0;\n\n int i = 1;\n while (i < M) {\n if (pattern[i] == pattern[len]) {\n len++;\n lps[i] =... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"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,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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"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,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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n const int mod = 1e9 + 9;\n const int B = 31;\n static const int N = 5e5 + 5;\n int p[N];\n\n void init() {\n p[0] = 1;\n for (int i = 1; i < N; i++) {\n p[i] = 1LL * p[i - 1] * B % mod;\n }\n }\n\n vector<int> hash(string s) {... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class StringSearch {\n vector<int> b;\n string t, p;\n public:\n StringSearch(string text, string pattern) {\n t = text;\n p = pattern;\n b.assign(p.length() + 1, 0);\n }\n\n void kmpPreProcess() {\n int i =0, j =-1;\n b[0] = -1;\n while(i <... |
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 <= i <= 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 if(s.size() < a.size() || s.size() < b.size()) return {};\n int n = s.size();\n int mod = 1e9 + 9;\n long long p = 31;\n vector<long long> pow(n, 1);\n for(int i=1 ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int>lpf(string word){\n vector<int>ans(word.size());\n int length=0;\n int i=1;\n while(i<word.size()){\n if(word[i]==word[length]){\n length++;\n ans[i]=length;\n 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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findlps(string pat) {\n int n = pat.size();\n vector<int> lps(n, 0);\n int len = 0;\n int i = 1;\n \n while (i < n) {\n if (pat[i] == pat[len]) {\n len++;\n lps[i] = len;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int> findlps(string pat) {\n int n = pat.size();\n vector<int> lps(n, 0);\n int len = 0;\n int i = 1;\n \n while (i < n) {\n if (pat[i] == pat[len]) {\n len++;\n lps[i] = len;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"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,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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n\n vector<int> longestPrefixSuffix(string &str) {\n vector<int> A(str.size(), 0);\n int j = 0, i = 1;\n while(i < str.size()) {\n if(str[i] == str[j]) {\n A[i] = j+1;\n j++;\n i++;\n } else... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int> kmp(string pat, string_view text) {\n int patsize = pat.size();\n pat.reserve(pat.size() + 1 + text.size());\n pat += '#';\n pat += text;\n\n vector<int> dp(pat.size() + 1);\n dp[0] = -1;\n vector<int> res;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "// 16:02\n\nconst int base = 37;\n\nclass Solution {\npublic:\n int md = 1000000007;\n vector<int> getMatchingIndexes(const string& s, const string& a) {\n long long oriHs = 0;\n long long power = 1;\n for (int i=0; i<a.size(); i++) {\n oriHs = (oriHs * base + (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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\nprivate:\n vector<int> computeMatches(string& p, string& s){\n string ps = p + \"#\" + s;\n int psLen = ps.length();\n int pLen = p.length();\n\n vector<int> matches;\n vector<int> z(psLen);\n int l = 0;\n int r = 0;\n for(int i =... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n void printArr(vector<int> &arr){\n for(int i = 0; i<arr.size(); i++) cout<<arr[i]<<\" \";\n cout<<'\\n';\n }\n void findLps(string &s, vector<int> &lps) {\n int n = s.size();\n lps[0] = 0; // The first character's LPS is always 0\n 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 <= i <= 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 int lenS = s.size();\n int lenA = a.size();\n int lenB = b.size();\n\n vector<int> lpsA(lenS + lenA + 1, 0);\n vector<int> lpsB(lenS + lenB + 1, 0);\n\n string kmpA... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n void printArr(vector<int> &arr){\n for(int i = 0; i<arr.size(); i++) cout<<arr[i]<<\" \";\n cout<<'\\n';\n }\n void findLps(string &s, vector<int> &lps){\n int n = s.size();\n int i = 0;\n for(int j = 1; j<n; j++){\n // cout... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n void printArr(vector<int> &arr){\n for(int i = 0; i<arr.size(); i++) cout<<arr[i]<<\" \";\n cout<<'\\n';\n }\n void findLps(string &s, vector<int> &lps) {\n int n = s.size();\n lps[0] = 0; // The first character's LPS is always 0\n 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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int>KMPAlgorithm(string &s) {\n \n int n=s.size();\n vector<int>lps(n,0); //longest prefix that matches suffix\n\n for(int i=1;i<n;i++) {\n int prevIndex = lps[i-1];\n\n while(prevIndex > 0 && s[i] != s[prevIndex]) {... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int> func(string &s, string &a) {\n vector<int>ans;\n int size = a.size();\n a.push_back('#');\n a.insert(a.end(), s.begin(), s.end());\n vector<int>lps(a.size(), 0);\n int temp = 0;\n for(int i = 1; i < lps.size(); ++i)... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "\n\ntypedef long long ll;\nconstexpr ll mod(ll a, ll n) { return (a % n + n) % n; }\nconstexpr int extEuclid(int a, int b, int& x, int& y) { // pass x and y by ref\n ll xx = y = 0;\n ll yy = x = 1;\n while (b) { // repeats until b == 0\n ll q = a / b;\n tie(a, b) = tuple(b, a % b);... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "vector<int> zfunc(string s) {\n int l, r;\n l = r = 0;\n vector<int> z(s.size());\n\tz[0] = 0;\n \n\tfor (int i = 1; i < s.size(); i++) {\n\t\tif (i <= r) {\n\t\t\tz[i] = min(r - i + 1, z[i - l]);\n\t\t}\n\t\twhile (z[i] + i < s.size() && s[z[i]] == s[z[i] + i]) z[i]++;\n\t\tif (r < i + z[i] - 1) ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n int compute_pi(int i, vector <int> &pi, string &P){\n if(i<=1) return 0;\n //pi[i] -> length of the longest prefix of P[1...i], which is also a suffix of P[1...i]\n int k = pi[i-1];\n while(P[k+1]!=P[i] && k>0) k = pi[k];\n if(P[k+1]==P[i]) return k+1;\n ret... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\n\nvector<int> kmp(string &s){\n\n int n = s.size();\n vector<int> lps(n, 0);\n for(int i = 1; i < n; i++){\n\n int prev_ind = lps[i-1];\n\n while(prev_ind > 0 && s[i] != s[prev_ind]){\n prev_ind = lps[prev_ind - 1];\n }\n\n lps[i] = prev_ind... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n struct hash {\n int n, mod, k;\n string s;\n vector<int> base, powk;\n\n void init(int n_, int k_, int mod_, const string& s) {\n n = n_;\n k = k_;\n mod = mod_;\n this->s = s;\n base.resize(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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n\n void zarr(string s, vector<int> &z) {\n int n=s.size();\n int l,r,k;\n l=r=0;\n int i;\n for(i=1;i<n;i++) {\n if(i>r) {\n l=r=i;\n while(r<n && s[r]==s[r-l]) {\n r++;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\nprivate:\n int getRangeSum(vector<int>& prefSum, int l, int r){\n if(l > r){\n return 0;\n }\n if(l == 0){\n return prefSum[r];\n }\n return (prefSum[r] - prefSum[l - 1]);\n }\n \n vector<bool> zAlgorithm(string p, strin... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n vector<int>kmp(string s){\n int n=s.size();\n vector<int>lps(n,0);\n for(int i=1;i<n;i++){\n int prev_ind=lps[i-1];\n while(prev_ind>0 and s[prev_ind]!=s[i]) prev_ind=lps[prev_ind-1];\n lps[i]=prev_ind +(s[prev_ind]==s[i] ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n // String : a a b a a c a a b a a d\n // LPS : 0 1 0 1 2 0 1 2 3 4 5 0\n\n // String : a a b # a a b a a b a a b\n // LPS : 0 1 0 0 1 2 3 1 2 3 1 2 3\n\n // Prefix that matches any subtsring of the string\n // Largest prefix that matches a suf... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 2 | {
"code": "class Solution {\npublic:\n // Largest prefix that matches a suffix\n vector<int> kmp(string s){\n vector<int> lps(s.size(), 0);\n\n for(int i=1;i<lps.size();i++){\n int prev_idx = lps[i-1];\n while(prev_idx>0 && s[i] != s[prev_idx]){\n prev_idx = lp... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "// class Solution {\n// public:\n// vector<int> beautifulIndices(string s, string a, string b, int k) {\n \n// }\n// };\n\nclass Solution {\npublic:\n\n vector<int> kmp(string s)\n {\n vector<int> lps(s.size(), 0);\n for(int i=1 ; i<lps.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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "vector<int> zfunc(string s) {\n int l, r;\n l = r = 0;\n vector<int> z(s.size());\n\tz[0] = 0;\n \n\tfor (int i = 1; i < s.size(); i++) {\n\t\tif (i <= r) {\n\t\t\tz[i] = min(r - i + 1, z[i - l]);\n\t\t}\n\t\twhile (z[i] + i < s.size() && s[z[i]] == s[z[i] + i]) z[i]++;\n\t\tif (r < i + z[i] - 1) ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n void FillLPS(vector<int>&LPS, string& needle)\n {\n LPS[0] = 0;\n int i = 0;\n int j = 1;\n while(j<needle.length())\n {\n if(needle[j] == needle[i])\n {\n i++;\n LPS[j] = i;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n void FillLPS(vector<int>&LPS, string& needle)\n {\n LPS[0] = 0;\n int i = 0;\n int j = 1;\n while(j<needle.length())\n {\n if(needle[j] == needle[i])\n {\n i++;\n LPS[j] = i;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n void computeLps(vector<int>& lps, string& a) {\n int m = a.size();\n int len = 0;\n int i = 1;\n while (i < m) {\n if (a[i] == a[len]) {\n len ++;\n lps[i] = len;\n i ++;\n } else {... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "int mod = (1e9) + 7;\nvector<int> p;\nvector<int> q;\nvoid calcPower()\n{\n p.push_back(1);\n long long temp = 1;\n for (int i = 1; i <= 500000; i++)\n {\n temp = (temp * 31) % mod;\n p.push_back(temp);\n }\n q.push_back(1);\n temp = 1;\n for (int i = 1; i <= 500000; i... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "void hashing(string &s,vector<long long int>&h,vector<long long int>&pp){\n int n = s.length();\n h[0] = s[0]-96;\n long long int mod = 1e9+9;\n long long int prime = 31;\n for(int i=1;i<n;i++){\n long long int t = s[i]-96;\n h[i] = (h[i-1] + (t*pp[i])%mod)%mod;\n }\n}\n\ncl... |
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 <= i <= 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& a)\n {\n string sa=a;\n sa+='#';\n sa+=s;\n vector<int>lps(sa.size(),0);\n for(int i=1;i<sa.size();i++)\n {\n int prev_ind=lps[i-1];//go to max prefix match of previous element and try ... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n vector<int> KMPSearch(string pat, string txt) {\n int M = pat.size();\n int N = txt.size();\n vector<int> a;\n\n vector<int> lps(M);\n\n auto computeLPSArray = [&](string pat, int M, vector<int>& lps) {\n int len = 0;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n vector<int> KMPSearch(string pat, string txt) {\n int M = pat.size();\n int N = txt.size();\n vector<int> a;\n\n vector<int> lps(M);\n\n auto computeLPSArray = [&](string pat, int M, vector<int>& lps) {\n int len = 0;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n vector<int> KMPSearch(string pat, string txt) {\n int M = pat.size();\n int N = txt.size();\n vector<int> a;\n\n vector<int> lps(M);\n\n auto computeLPSArray = [&](string pat, int M, vector<int>& lps) {\n int len = 0;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n vector<int> KMPSearch(string pat, string txt) {\n int M = pat.size();\n int N = txt.size();\n vector<int> a;\n\n vector<int> lps(M);\n\n auto computeLPSArray = [&](string pat, int M, vector<int>& lps) {\n int len = 0;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n vector<int> KMPSearch(string pat, string txt) {\n int M = pat.size();\n int N = txt.size();\n vector<int> a;\n\n vector<int> lps(M);\n\n auto computeLPSArray = [&](string pat, int M, vector<int>& lps) {\n int len = 0;\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 <= i <= 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 string sa = a + \"#\" + s;\n string sb = b + \"#\" + s;\n\n int len = s.length();\n\n int lena = sa.length();\n int lenb = sb.length();\n\n vector<int> kmpa(lena+1,... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n vector<int> kmp(string t,string p){\n int m=p.size();\n p+='#';\n p+=t;\n int n=p.size();\n vector<int> pre(n);\n for(int i=1;i<n;i++){\n int j=pre[i-1];\n while(j && p[i]!=p[j])\n j=pre[j-1];\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <algorithm>\n#include <cmath>\n\nusing namespace std;\n\nvector<int> rk(const string &t, const string &s) {\n const uint64_t p = 31;\n vector<uint64_t> p_pow(max(s.size(), t.size()));\n p_pow[0] = 1;\n for (size_t i = 1; i < p_pow.size(); ++i) {\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "#include <vector>\n#include <string>\n#include <algorithm>\n#include <cmath>\n\nusing namespace std;\n\nvector<int> rk(const string &t, const string &s) {\n const uint64_t p = 31;\n vector<uint64_t> p_pow(max(s.size(), t.size()));\n p_pow[0] = 1;\n for (size_t i = 1; i < p_pow.size(); ++i) {\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\n vector<int> zalgo(string &s){\n int n=s.length();\n vector<int> v(n,0);\n int l=0,r=0;\n for(int i=1;i<n;i++){\n if(i<r){\n v[i]=min(r-i,v[i-l]);\n }\n while(i+v[i]<n && s[v[i]]==s[v[i]+i]) v[i]++;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\n vector<int> zalgo(string &s){\n int n=s.length();\n vector<int> v(n,0);\n int l=0,r=0;\n for(int i=1;i<n;i++){\n if(i<r){\n v[i]=min(r-i,v[i-l]);\n }\n while(i+v[i]<n && s[v[i]]==s[v[i]+i]) v[i]++;\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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "typedef long long int ll;\n\nconst int MOD = 1e9+9;\nconst int P = 31;\n\n// Pattern = 's', Text = 't'\nvector<int> RabinKarp(const string& s, const string& t) {\n int S = s.size(), T = t.size();\n\n vector<ll> p_pow(max(S, T)); \n p_pow[0] = 1; \n for (int i = 1; i < p_pow.size(); i++) \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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\n using ll = long long;\n long long BASE = 101;\n long long mod = 1e9 + 7;\n \n vector<int> rabinKarp(const string& s, const string& p) {\n \n vector<int> ans;\n\n int n = s.size();\n int pn = p.size();\n \n if (pn > 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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\n using ll = long long;\n long long BASE = 101;\n long long mod = 1e9 + 7;\n \n vector<int> rabinKarp(const string& s, const string& p) {\n \n vector<int> ans;\n\n int n = s.size();\n int pn = p.size();\n \n if (pn > 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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst ll BASE = 31;\nconst ll MOD = 1e9+7;\n\nclass Solution {\npublic:\n vector<ll> computePowers(int n) {\n vector<ll> powers(n);\n powers[0] = 1;\n for(int i = 1; i < n; i++) {\n powers[i] = (powe... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\nusing ll = long long;\n\nconst ll BASE = 31;\nconst ll MOD = 1e9+7;\n\nclass Solution {\npublic:\n vector<ll> computePowers(int n) {\n vector<ll> powers(n);\n powers[0] = 1;\n for(int i = 1; i < n; i++) {\n powers[i] = (powe... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n int brr[500001]={0};\nvector<int> rabin_karp(string const& s, string const& t) \n{\n const int p = 31; \n const int m = 1e9 + 9;\n int S = s.size(), T = t.size();\n\n vector<long long> p_pow(max(S, T)); \n p_pow[0] = 1; \n for (int i = 1; i < (int)p_pow.size... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n/* Macros {{{ */\n/* A lot of this is from some of Benq's submissions\n [https://codeforces.com/profile/Benq]\n Ugly af to the eyes, but with vim fold its barable\n Hopefully c++20 concepts can make all this stuff must cleaner */\n\n/* Basics {{{ ... |
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 <= i <= 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,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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n void getPatternMatchingIndex(string& s, string& a, vector<int>& v){\n string t = a + \"@\" + s;\n vector<int> lps(1, 0);\n for(int i = 1; i < t.size(); ++i){\n int ind = lps[i-1]; \n while(ind > 0 && t[ind] != t[i]) { ind = lps[ind-1]; }\n lps.pu... |
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 <= i <= s.length - a.length</code></li>
<li><code>s[i..(i + a.length - 1)]... | 3 | {
"code": "class Solution {\npublic:\n void getPatternMatchingIndex(string& s, string& a, vector<int>& v){\n string t = a + \"@\" + s;\n vector<int> lps(1, 0);\n for(int i = 1; i < t.size(); ++i){\n int ind = lps[i-1]; \n while(ind > 0 && t[ind] != t[i]) { ind = lps[ind-1]; }\n lps.pu... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 0 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int mini = 1e9;\n int ind1=0, ind2, ind3;\n for(int i=1; i<nums.size(); i++){\n for(int j=i+1; j<nums.size(); j++){\n int sum = nums[0] + nums[i] + nums[j];\n if(sum<mini){\n ... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 0 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int ans = nums[0];\n int smaller = 100;\n int small = 100;\n for(int i=1;i<nums.size();i++){\n if(nums[i]<small){\n smaller = small;\n small = nums[i];\n }\n... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 0 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int n = nums.size();\n if (n < 3) return 0; // Not enough elements to split into 3 subarrays\n \n int min_cost = INT_MAX;\n \n \n for (int i = 0; i < n - 2; ++i) {\n for (int j = i + 1; j < n - 1; ++j) {\... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 0 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums)\n {\n int min1 = nums[0];\n int min2 = INT_MAX, min3 = INT_MAX;\n for(int i=1;i<nums.size();i++)\n {\n if(nums[i] <= min2)\n {\n min3 = min2;\n min2= nums[i];... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 0 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int n = nums.size();\n int ans = nums[0]; // first elemnt will be taken as we need subarrays\n int min1 = INT_MAX;\n int min2 = INT_MAX;\n for(int i = 1; i < n; i++) {\n int curr = nums[i];\n... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 0 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int first = INT_MAX;\n int second = INT_MAX;\n for (int i = 1; i < nums.size(); ++i) {\n if (nums[i] < first) {\n second = first;\n first = nums[i];\n } else if (nu... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 1 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int n = nums.size();\n if (n == 3) return nums[0] + nums[1] + nums[2];\n int res = INT_MAX;\n for (int i = 1; i < n - 1; ++i) {\n for (int j = i + 1; j < n; ++j) {\n res = min(res, nu... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 1 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int n = nums.front();\n sort(nums.begin(), nums.end());\n if(n > nums[2]){\n return nums[0] + nums[1] + n;\n }else{\n return nums[0] + nums[1] + nums[2];\n }\n }\n};",
"memory... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 1 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n sort(nums.begin()+1,nums.end());\n int count=nums[0]+nums[1]+nums[2];\n return count;\n }\n};",
"memory": "30300"
} |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 1 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int min_cost = nums[0];\n\n nums.erase(nums.begin());\n sort(nums.begin(), nums.end());\n\n min_cost += nums[0];\n min_cost += nums[1];\n\n return min_cost;\n }\n};",
"memory": "30300"
} |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 2 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n std::sort(nums.begin()+1, nums.end());\n return nums[0] + nums[1] + nums[2];\n }\n};",
"memory": "30400"
} |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 3 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n int sum=0;\n vector<int> v(nums.size(),0);\n for(int i=1;i<nums.size();i++){\n v[i-1]=nums[i];\n }\n sort(v.begin(),v.end());\n sum=nums[0]+v[1]+v[2];\n return sum;\n }\n};",... |
3,263 | <p>You are given an array of integers <code>nums</code> of length <code>n</code>.</p>
<p>The <strong>cost</strong> of an array is the value of its <strong>first</strong> element. For example, the cost of <code>[1,2,3]</code> is <code>1</code> while the cost of <code>[3,4,1]</code> is <code>3</code>.</p>
<p>You need t... | 3 | {
"code": "class Solution {\npublic:\n int minimumCost(vector<int>& nums) {\n vector<int>a;\n for(int i=1;i<nums.size();i++){\n a.push_back(nums[i]);\n }\n sort(a.begin(),a.end());\n return a[0]+a[1]+nums[0];\n }\n};",
"memory": "30600"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.