id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,332
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> <p>In one operation, you will:</p> <ul> <li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li> <li>Remove <code>x</code> and <code>y</code> from <code>nums</code...
1
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n int ans = 0;\n priority_queue<long long,vector<long long>,greater<long long>> q;\n for(int n: nums) q.push(n);\n while(q.top() < k){\n long long x = q.top();\n q.pop();\n ...
3,332
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> <p>In one operation, you will:</p> <ul> <li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li> <li>Remove <code>x</code> and <code>y</code> from <code>nums</code...
3
{ "code": "class compare{\n public:\n bool operator()(long long int a, long long int b){\n return a > b ; // agr b small hai to return true. for min heap.\n }\n};\nclass Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n // min heap \n priority_queue<long long int,v...
3,332
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> <p>In one operation, you will:</p> <ul> <li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li> <li>Remove <code>x</code> and <code>y</code> from <code>nums</code...
3
{ "code": "\n#define MOD 100000007\n\nclass Solution {\npublic:\n int minOperations(std::vector<int>& nums, int k) {\n std::priority_queue<long long, std::vector<long long>,\n std::greater<long long>>\n minheap1;\n std::priority_queue<long long, std::vector<long ...
3,332
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> <p>In one operation, you will:</p> <ul> <li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li> <li>Remove <code>x</code> and <code>y</code> from <code>nums</code...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n vector<long long>longnums(nums.begin(),nums.end());\n priority_queue<long long,vector<long long>,greater<long long>>maxh;\n int n=longnums.size();\n int c=0;\n for(int i=0;i<n;i++)\n {\n maxh.push(longnu...
3,332
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> <p>In one operation, you will:</p> <ul> <li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li> <li>Remove <code>x</code> and <code>y</code> from <code>nums</code...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums, int k) {\n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,\n greater<pair<long long, long long>>>\n pq;\n for (int i = 0; i < nums.size(); i++) {\n pq...
3,332
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, and an integer <code>k</code>.</p> <p>In one operation, you will:</p> <ul> <li>Take the two smallest integers <code>x</code> and <code>y</code> in <code>nums</code>.</li> <li>Remove <code>x</code> and <code>y</code> from <code>nums</code...
3
{ "code": "#define ll long long int\nclass Solution {\npublic:\n int minOperations(vector<int>& a, int k) {\n int ans=0;\n multiset<ll> s;\n for(auto val:a){\n if(val<k) s.insert(val);\n }\n while(s.size()>=2){\n ll v1 = *s.begin();\n s.erase(s.begin());\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
0
{ "code": "class Solution {\npublic:\n int freq[128] = {0}, nuc, nck;\n\n // Function to count complete substrings with given properties\n int func(string& s, int lo, int hi, int& k) {\n int ans = 0;\n\n // Iterate over different substring lengths\n for (int i = 1; i < 27; i++) {\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
0
{ "code": "class Solution {\n\tpublic:\n\t\tint countCompleteSubstrings(const string &w, int k) {\n int res = 0;\n for (int chars = 1; chars <= min((int)w.size() / k, 26); ++chars) {\n int cnt[26] = {}, exact = 0, sz = chars * k;\n for (int i = 0, j = 0; i < w.size(...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int solve(string s ,int k){\n int cnt=0;\n int n=s.length();\n for(int i=1; i<=26; i++){\n int windowsize=i*k;\n if(windowsize<=n)\n {\n bool flag=false;\n unordered_map<char,int>mp;\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n /*\n 1. each character exactly k times\n 2. dist with two adj char at most 2\n */\n int n = word.size();\n int cnt = 0;\n for(int i=0; i<n; i++){\n int j=i+...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int res = 0;\n for(int num_char = 1; num_char <= 26; ++num_char) {\n int len = num_char * k;\n // unordered_map<char, int> cts;\n vector<int> cts(26+'a', 0);\n int l=...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int res = 0;\n for(int num_char = 1; num_char <= 26; ++num_char) {\n int len = num_char * k;\n // unordered_map<char, int> cts;\n vector<int> cts(26+'a', 0);\n int l=...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n void buildTree(vector<int>&tree,vector<int>&a,int index,int s,int e)\n{\n\t//base case\n\tif(s>e)\n\t\treturn;\n\t//reached leaf node\n\tif(s==e)\n\t{\n\t\ttree[index]=a[s];\n\t\treturn ;\n\t}\n\t//now build the segment tree in bottom up manner\n\tint m = (s+e)/2;\n\tbuildT...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n void buildTree(vector<int>&tree,vector<int>&a,int index,int s,int e)\n{\n\t//base case\n\tif(s>e)\n\t\treturn;\n\t//reached leaf node\n\tif(s==e)\n\t{\n\t\ttree[index]=a[s];\n\t\treturn ;\n\t}\n\t//now build the segment tree in bottom up manner\n\tint m = (s+e)/2;\n\tbuildT...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n bool check(vector<int>& cnt, int k) {\n for (int i = 0; i < 26; i++) \n if (cnt[i] && cnt[i] != k)\n return 0;\n return 1;\n }\n\n int get(int len, int k, string s) {\n if (len > s.size()) return 0;\n\n // cout << \"...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n bool check(vector<int>& cnt, int k) {\n for (int i = 0; i < 26; i++) \n if (cnt[i] && cnt[i] != k)\n return 0;\n return 1;\n }\n\n int get(int len, int k, string s) {\n if (len > s.size()) return 0;\n \n int n...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "#define ll long long int\n#define pb push_back\nclass Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n /*No sliding Window\n size:- 1*k,2*k,3*k upto 26*k ke liye check karna hai\n */\n vector<ll> vs(26,0);\n ll cnt=0;\n for(auto it:word...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n vector<string> strs;\n string temp = \"\";\n temp += word[0];\n for(int i = 1; i < word.length(); i++) {\n if(abs(word[i] - word[i-1]) > 2) {\n strs.push_back(temp);\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n auto canBeEnd = [&](int i) {\n return i > 0 && abs(word[i]-word[i-1]) <= 2;\n };\n\n int ans = 0;\n auto count = [&](string_view s) {\n for (int m=1; m<=26; m++) { // 此 win 有...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n // checking the frequency vector so that there \n // are j characters and each character occurs k times..\n bool check(vector<int> & freq, int &j, int &k)\n {\n int ct = 0;\n for(int i = 0; i < freq.size();i++)\n {\n if (freq[i] == 0) ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "\nclass Solution {\npublic:\n // checking the frequency vector so that there \n // are j characters and each character occurs k times..\n bool check(vector<int> & freq, int &j, int &k)\n {\n int ct = 0;\n for(int i = 0; i < freq.size();i++)\n {\n if (freq[i] == 0...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n bool check(vector<int> & freq, int &j, int &k){\n int ct = 0;\n for(int i = 0; i < freq.size();i++){\n if (freq[i] == 0) continue;\n if (freq[i] != k) return false;\n else ct++;\n }\n if (ct > j) return false;\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n // checking the frequency vector so that there \n // are j characters and each character occurs k times..\n bool check(vector<int> & freq, int &j, int &k)\n {\n int ct = 0;\n for(int i = 0; i < freq.size();i++)\n {\n if (freq[i] == 0) ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) \n {\n int n = word.size();\n int ret = 0;\n for (int i=0; i<n; )\n {\n int j = i+1;\n while (j<n && abs(word[j]-word[j-1])<=2)\n j++;\n ret += helpe...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) \n {\n int n = word.size();\n int res = 0;\n for (int i=0; i<n; )\n {\n int j = i+1;\n while (j<n && abs(word[j]-word[j-1])<=2)\n j++;\n res += helpe...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
2
{ "code": "// Idea: for each j*k, use a sliding window of size j*k\n// hash table/map index for each letter.\n// if the gap between a consecutive pair of chars is > 2,\n// then it splits the problem into two independent subproblems.\nclass Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\n\t\tusing Freq = array<int, 26>;\n\tpublic:\n\t\tint countCompleteSubstrings(string word, int k) {\n\t\t\tint n = word.size();\n\t\t\tvector<Freq> freqs(n + 1);\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tfreqs[i+1] = freqs[i];\n\t\t\t\tfreqs[i+1][word[i] - 'a']++;\n\t\t\t}\n\t\t\tint l =...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\n\t\tusing Freq = array<int, 26>;\n\tpublic:\n\t\tint countCompleteSubstrings(string word, int k) {\n\t\t\tint n = word.size();\n\t\t\tvector<Freq> freqs(n + 1);\n\t\t\tfor(int i = 0; i < n; i++){\n\t\t\t\tfreqs[i+1] = freqs[i];\n\t\t\t\tfreqs[i+1][word[i] - 'a']++;\n\t\t\t}\n\t\t\tint l =...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "// Idea: for each j*k, use a sliding window of size j*k\n// hash table/map index for each letter.\n// if the gap between a consecutive pair of chars is > 2,\n// then it splits the problem into two independent subproblems.\nclass Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int ans=0;\n for(int i=k;i<=26*k && i<=word.length();i+=k){\n unordered_map<char,int>charFreq;\n int startInd=-1;\n for(int j=0;j<word.length();j++){\n if(startIn...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int ans=0;\n for(int i=k;i<=26*k && i<=word.length();i+=k){\n unordered_map<char,int>charFreq;\n int startInd=-1;\n for(int j=0;j<word.length();j++){\n if(startIn...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string s, int k) {\n vector<int> brk(s.size());\n for(int i=1;i<s.size();i++){\n brk[i]=brk[i-1];\n if(abs(int(s[i])-int(s[i-1]))>2)\n brk[i]++;\n }\n vector<array<int,26>> cnt(s.size...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int n = word.length();\n int ans = 0;\n\n vector<array<int,26>> pre(n);\n pre[0][word[0]-'a'] = 1;\n for (int i = 1; i < n; ++i) {\n for (int j = 0; j < 26; ++j)\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int n = word.size();\n vector<vector<int>> pre(26,vector<int>(n));\n int b4 = word[0];\n int res = 0;\n pre[word[0] - 'a'][0]++;\n for(int i = 1;i<n;i++){\n for(int j = 0;...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n // dp? keep track of how many substrings include last letter, have abs diff <= 2,\n // and total <= k, via set of 26-tuple's. Then, if totals all equal k, remove.\n vector<array<int, 26>> charCounts;\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n\n int getSubsFromPos(string &word, int k, int startPos, map<char, int> &freq, int i)\n {\n if(startPos + i * k > word.size())\n return 0;\n int dist = 0, ans = 0;\n for(int j = startPos; j < i * k + startPos && j < word.size(); j++)\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) \n {\n int n = word.size();\n int ret = 0;\n for (int i=0; i<n; )\n {\n int j = i+1;\n while (j<n && abs(word[j]-word[j-1])<=2)\n j++;\n ret += helpe...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n \n int n = word.size();\n int res = 0;\n\n for (int i = 0; i < n;) {\n int j = i + 1;\n while (j < n && abs(word[j] - word[j - 1]) <= 2)\n j++;\n \n...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) \n {\n int n = word.size();\n int ret = 0;\n for (int i=0; i<n; )\n {\n int j = i+1;\n while (j<n && abs(word[j]-word[j-1])<=2)\n j++;\n ret += helpe...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int n=word.size();\n\n map<char,int> mp;\n int unique=0;\n for(auto e:word)\n {\n mp[e]++;\n if(mp[e]==1)\n unique++;\n }\n\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int ans=0;\n for(int i=k;i<=26*k && i<=word.length();i+=k){\n map<char,int>charFreq;\n int startInd=-1;\n for(int j=0;j<word.length();j++){\n if(startInd!=j-1 && ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "#include <vector>\n#include <string>\n#include <map>\n\nclass Solution {\nprivate:\n bool is_same_frequency(const std::map<char, int>& freq, int k) {\n for (const auto& p : freq) {\n if (p.second != k && p.second != 0)\n return false;\n }\n return true;\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\nint check(int i , int j ,int k , string &word , vector<vector<int>>&cnts){\n if(i == 0){\n for(int l = 0 ; l < 26 ; l++){\n if(!(cnts[j][l] == k or cnts[j][l] == 0))return 0 ; \n }\n }else{\n for(int l = 0 ; l < 26 ; l++){\n if(!((cnts[...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\n\npublic:\n int countCompleteSubstrings(string s, int k) {\n int n = s.size();\n vector<vector<int>> ps(n + 1, vector<int>(26, 0));\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j < 26; j++)\n ps[i][j] = ps[i - 1][j];\n\n p...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\n int solve(int start,int end,string &word,int k){\n int ans = 0;\n for(int charr =1;charr<=26 && charr*k<=end-start+1;charr++){\n int wl = charr*k;\n vector<int>coun(26);\n int i=start;\n int sav = 0;\n for(int j=star...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n\n int helper(string word, int len, vector<vector<int>>& prefixCnt, int k) {\n \n int n = word.size();\n int dp[n + 1];\n for(int i = 0; i < n; i++) {\n dp[i] = 1;\n }\n\n for(int i = 1; i < n; i++) {\n int prevVa...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n string s = word ; \n int n = s.size() ; \n vector<vector<int>>arr(n + 1, vector<int>(26 , 0 )) ; \n for (int i = 0; i < n; ++i)\n {\n arr[i+1] = arr[i] ; \n arr[i+1][s...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int n = word.length();\n // map<int,int>mp;\n vector<int>v1;\n for(int i=0;i<n-1;i++){\n if(word[i+1]-word[i]>2) v1.push_back(i); \n else if(word[i+1]-word[i]<-2) v1.push_bac...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\n public:\n int countCompleteSubstrings(string word, int k) {\n const int uniqueLetters =\n unordered_set<char>{word.begin(), word.end()}.size();\n int ans = 0;\n\n for (int windowSize = k;\n windowSize <= k * uniqueLetters && windowSize <= word.length();\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\n public:\n int countCompleteSubstrings(string word, int k) {\n const int uniqueLetters =\n unordered_set<char>{word.begin(), word.end()}.size();\n int ans = 0;\n\n for (int windowSize = k;\n windowSize <= k * uniqueLetters && windowSize <= word.length();\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n bool freqcheck(vector<int> freq,int k){\n for(int i=0;i<26;i++){\n if(freq[i]!=0 && freq[i]!=k){\n return false;\n }\n }\n return true;\n }\n bool adjacentcheck(string &word,int st,int end){\n for(int i=st...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int sliding_window(string& s, vector<vector<int>>& p, int count, int k) {\n // count -> Number of unique characters\n // window of size count*k\n int sz = 0, cntk = 0, ans = 0;\n for(auto& it: p) {\n int left = it[0], right = it[0], sz =...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int n=word.size();\n vector<vector<int>>freqs(word.size()+1,vector<int>(26,0));\n for(int i=0;i<word.size();i++){\n freqs[i+1]=freqs[i];\n freqs[i+1][word[i]-'a']++;\n }\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n int n = word.size();\n vector<vector<int>>freq(n+1,vector<int>(26,0));\n for(int i=0;i<n;i++){\n freq[i+1] = freq[i];\n freq[i+1][word[i]-'a']++;\n }\n int l=0;\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\nprivate:\n vector<int> sub(vector<int>& a, vector<int>& b){\n vector<int> c(26,0);\n for(int i=0; i<26; i++) c[i]=a[i]-b[i];\n return c;\n }\npublic:\n int countCompleteSubstrings(string word, int k) {\n vector<int> hash(26,0);\n vector<int> dif...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n vector<int> sep;\n int n = word.size();\n sep.push_back(0);\n for (int i = 1; i < n; i++) {\n if (abs(word[i] - word[i - 1]) > 2) {\n sep.push_back(i);\n }\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string s, int k) {\n int n=s.size(),ans=0,chk=-1;\n vector<vector<int>>a(26);\n vector<vector<int>>v(n,vector<int>(26));\n\n for(int i=0;i<n;i++){\n if(i) v[i]=v[i-1];\n v[i][s[i]-'a']++;\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n vector<int>alpha(26,0);\n vector<vector<int>> dp;\n int n = word.size();\n if(n==1) return 1;\n for(int i=0; i<n; i++){\n alpha[word[i]-'a']++;\n dp.push_back(alpha);\...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n if (word.size() == 1){return (k == 1);}\n vector <pair <int, int>> intervals;\n int last = 0, tot = 0;\n unordered_map <char, int> freq;\n int ma = 1; freq[word[0]]++;\n for (int i =...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n int countCompleteSubstrings(string word, int k) {\n if (word.size() == 1){return (k == 1);}\n vector <pair <int, int>> intervals;\n int last = 0, tot = 0;\n unordered_map <char, int> freq;\n int ma = 1; freq[word[0]]++;\n for (int i =...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n\n vector<pair<int,int>> vec;\n\n int func(int x,string &word,int k){\n int ans=0;\n for(auto p:vec){\n int st=p.first;\n int end=p.second;\n int cnt=0;\n unordered_map<char,int> M;\n for(int i=st;i<=end;+...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> ranges;\n int f(int x,int k,string s){\n int ans=0;\n for(auto &it:ranges){\n int j=it[0],e=it[1];\n int cntk=0;\n unordered_map<char,int>mp;\n for(int i=it[0];j<=e;j++)\n\t\t\t{\n ...
3,223
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p> <p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p> <ul> <li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li> <li>The difference between two adjacent characte...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>vec;\n int func(int x,int k,string s)// Standard sliding window approach counting substrings with length x*k with each character occuring exactly k times \n\t{ \n int ans=0;\n for(auto &it:vec){\n int j=it[0],e=it[1];\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution {\n const int mod = 1e9 + 7;\n int fac[100000]{1};\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n long long i, p = 0, m = sick.size(), ans = 1;\n for (i = 1; i < n; i++) {\n fac[i] = ((long long)fac[i - 1] * i) % mod;\n }\n for (...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "const long long mod=1e9+7;\nconst int SIZE=100000;\nlong long fact[SIZE+1];\n\nlong long PowerMod(long long a,long long b)\n{\n long long ans=1;\n while(b!=0)\n {\n if((b&1)!=0)\n {\n ans=ans*a%mod;\n }\n a=a*a%mod;\n b>>=1;\n }\n return ans;\n}\...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n\n // void findfacts(unordered_map<int,int>& fact, int n){\n // fact[0]=1; fact[1]=1; fact[2]=2;\n \n // for(int i=3;i<=n;i++){\n // fact[i]= (1LL*i*fact[i-1])%mod;\n // }\n // }\n\n int exp(int base, int exp){\n...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n\n // void findfacts(unordered_map<int,int>& fact, int n){\n // fact[0]=1; fact[1]=1; fact[2]=2;\n \n // for(int i=3;i<=n;i++){\n // fact[i]= (1LL*i*fact[i-1])%mod;\n // }\n // }\n\n int exp(int base, int exp){\n...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "//[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13] a1,a5,a7,a13\n//(a2,a4,a6,a8),(a3),(a9),(a10)\n//[a2,a3,a4],[a6],[a18,a9,a10,a11,a12]\n//[0,1,2,3,4] 0,4\n//[1,2,3] ->3!/(3!/2*2*1)=6/(6-4)=6/2=\n//formula=n!/(n1!/pow(2,n1-1))*(n2!/pow(2,n2-1))....\nclass Solution {\npublic:\n long mod=1e9+7;\n long pow...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution\n{\n using ll = long long;\n\n ll mod = 1e9 + 7, fact[100005];\n\n long long modpow(long long a, long long b, long long p)\n {\n long long res = 1;\n while (b > 0)\n {\n if (b & 1)\n res = (res * a) % p;\n a = (a * a) % p;...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n\n // void findfacts(unordered_map<int,int>& fact, int n){\n // fact[0]=1; fact[1]=1; fact[2]=2;\n \n // for(int i=3;i<=n;i++){\n // fact[i]= (1LL*i*fact[i-1])%mod;\n // }\n // }\n\n int exp(int base, int exp){\n...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution {\npublic:\nlong mod=1e9+7;\nlong pow(int a,int b)\n{\n if(b==0)\n return 1;\n long powi=pow(a,b/2);\n if(b%2==0)\n return (powi*powi)%mod;\n else\n return (((powi*powi)%mod)*a)%mod;\n}\n int numberOfSequence(int n, vector<int>& sick) {\n long i,j,m=sick.size(),ans=1...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n long long power(long long a, long long b){\n if(b == 0){\n return 1;\n }\n long long res = power(a, b/2);\n if(b%2){\n long long temp = res*1LL*res;\n temp %= mod;\n temp *= a;\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "// Idea: DP and Math\n// * the count of distinct \"infection\" sequences where two bad cells enclose k\n// good cells: DP scheme: bellman equation: let f(l,r,k) be the # ways starting\n// from l cells infected from leftside, and r cells infected from rightside.\n// f(0,0,k) = f(1,0,k) + f(0,1,k);\n// f(l,r...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "constexpr int m = 100000;\nlong long fact[m+1], inv_fact[m+1], mod = 1000000007;\nbool init = false;\nclass Solution {\n // Time complexity O(slogm); Memory complexity O(m);\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n // (sum(segments))!/(multiply(for each segments!)) * 2 ^ (...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "constexpr int m = 100000;\nlong long fact[m+1], inv_fact[m+1], mod = 1000000007;\nbool init = false;\nclass Solution {\n // Time complexity O(slogm); Memory complexity O(m);\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n // (sum(segments))!/(multiply(for each segments!)) * 2 ^ (...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
0
{ "code": "const int MOD = 1e9 + 7;\nconst int MAX = 1e5 + 5; // Adjust this depending on the maximum value of n\n\nvector<long long> fact(MAX), inv_fact(MAX);\n\n// Function to calculate power with mod using binary exponentiation\nlong long power(long long a, long long b, long long mod) {\n long long res = 1;\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "#define ll long long\nclass Solution {\npublic:\n ll fact[100005], inv[100005];\n ll mod = 1e9 + 7;\n\n ll binpow(ll a, ll b) {\n ll res = 1;\n while (b) {\n if (b & 1)\n res = (res * a) % mod;\n a = (a * a) % mod;\n b >>= 1;\n }...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "#include <vector>\n#include <iostream>\n\nconst int MOD = 1000000007;\n\nstd::vector<long long> factorial, inv_factorial;\n\nlong long mod_exp(long long base, int exp, int mod) {\n long long result = 1;\n while (exp > 0) {\n if (exp % 2 == 1) result = (result * base) % mod;\n base = (ba...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "class Solution {\nprivate:\n const long long mod = 1e9+7;\n long long fact[100001];\n long long binExp(long long a, long long b)\n {\n long long res = 1;\n while (b)\n {\n if (b & 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b >>= 1;\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "class Solution {\nprivate:\n const long long mod = 1e9+7;\n long long fact[100001];\n long long binExp(long long a, long long b)\n {\n long long res = 1;\n while (b)\n {\n if (b & 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b >>= 1;\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "using LL = long long;\nclass Solution {\n LL power[100005];\n LL fact[100005];\n LL mod = 1e9+7;\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n /*\n j i\n x x x x x o x x x x x x o x x x x o x x x\n a b ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "using LL = long long;\nclass Solution {\n LL power[100005];\n LL fact[100005];\n LL mod = 1e9+7;\npublic:\n int numberOfSequence(int n, vector<int>& sick) \n {\n power[0] = 1;\n for (int i=1; i<=n; i++)\n power[i] = power[i-1]*2 % mod;\n \n fact[0] = 1;...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "// Time: precompute: O(max_n)\n// runtime: O(s + logn)\n// Space: O(max_n)\n\n// combinatorics\nvector<int> FACT = {1, 1};\nvector<int> INV = {1, 1};\nvector<int> INV_FACT = {1, 1};\nclass Solution {\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n int result = 1, total = ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "#define MOD 1000000007\n#define ll long long\n\nll fast_mul(ll a, ll b) {return ((a%MOD)*(b%MOD))%MOD;}\n\nll binpow(ll a, ll b) {\n if(b==0) return 1;\n int ans = binpow(a, b/2);\n ans = fast_mul(ans, ans);\n if(b%2){\n return fast_mul(ans, a);\n }\n return ans;\n}\n\nll mod_inv(l...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "#define ll long long\nconst int N = 100001;\n\n// array to store inverse of 1 to N\nll factorialNumInverse[N + 1];\n\n// array to precompute inverse of 1! to N!\nll naturalNumInverse[N + 1];\n\n// array to store factorial of first N numbers\nll fact[N + 1];\n\nll power[N + 1];\n\n// Function to precompute ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "class Solution {\npublic:\n long long mod= 1e9+7;\n long long fac(long long n){\n if(n==1) return 1;\n long long ans=(n*fac(n-1))%mod;\n return ans;\n }\n\n long long power(long long a, long long x){\n long long res=1;\n while(x){\n if(x%2){\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "class Solution {\npublic:\n\n const int M=1e9+7;\n\n vector<pair<int,int>> V;\n\n int binaryexp(int a,int b){\n int res=1;\n while(b){\n if(b&1)res=(res*1ll*a)%M;\n a=(a*1ll*a)%M;\n b=b/2;\n }\n return res;\n }\n\n int numberOfSequ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "class Solution {\npublic:\n static const int mod=1e9+7; // This is a prime number\n\n vector<int> fact;\n void factorialMod(int n){\n fact.assign(n+1, 1);\n for(int i=2; i<=n; i++){\n fact[i]=(long long)fact[i-1]*i%mod;\n }\n }\n // Find x, y, d such that ax +...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
1
{ "code": "#pragma GCC optimize(\"O3\", \"unroll-loops\")\nconst int mod=1e9+7; // This is a prime number\nclass Solution {\npublic:\n vector<int> fact;\n void factorialMod(int n){\n fact.assign(n+1, 1);\n for(int i=2; i<=n; i++){\n fact[i]=(long long)fact[i-1]*i%mod;\n }\n }\...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n const int mod=1e9+7;\n int binexp(int a,int b){\n long long ans=1,term=a;\n while(b){\n if(b&1)\n ans=(ans*term)%mod;\n term=(term*term)%mod;\n b/=2;\n }\n return ans;\n }\n int numberOfSeque...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "#define ll long long\nll MOD = 1e9 + 7;\nll _mul(ll x, ll y) { x %= MOD, y %= MOD; return (x * 1ll * y) % MOD; }\nll _pow(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0){\nll _tmp =_pow(x, y / 2); return _mul(_tmp, _tmp); } else return _mul(x, _pow(x, y - 1)); }\nll _inv(ll p) { return _pow(p, MOD...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n #define ll long long int\n #define mod (ll)(1e9+7)\n ll expo(ll a,ll b){\n if(b<=0)return 1;\n ll ans=expo(a,b/2);\n ans=(ans*ans)%mod;\n if(b%2)ans=(ans*a)%mod;\n return ans;\n }\n int numberOfSequence(int n, vector<int>& sick) ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n const ll mod = (1e9 + 7);\n ll pow(ll a, ll b) {\n ll base = a, cur = 0, l = 1, ans = 1;\n while ((l << cur) <= b) {\n if (((l << cur) & b) != 0) {\n ans = (ans * base) % mod;\n }\n base =...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n std::vector<long long> fac;\n long long M = std::pow(10, 9) + 7;\n\n long long power(long long v, long long p, long long mod) {\n long long result = 1;\n while (p > 0) {\n if (p % 2 == 1) {\n result = (result * v) % mod;\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\n vector<long long> fact;\n int mod = 1e9+7;\n\n void f() {\n fact[0] = 1LL;\n fact[1] = 1LL;\n for(int i = 2; i < fact.size(); i++) {\n fact[i] = (i * fact[i-1]) % mod;\n }\n }\n\n int pows(long long a, long long b) {\n long lon...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n\n int modulo = 1e9 + 7;//这玩意是质数\n int modPow(long long base,int p,int mod) {\n long long res = 1;\n while(p>0) {\n if(p%2) {\n res = (res * base) % mod;\n }\n base = (base * base) % mod;\n p /= 2;\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n int mod = 1e9+7;\n vector<int> segmentSize;\n\n for (int i = 0; i < sick.size(); i++) {\n int size = sick[i]-(i > 0? sick[i-1]:-1)-1;\n if (size > 0) segmentSize.push_back(size);\n ...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "typedef unsigned long long int ulli;\n\nclass Solution {\npublic:\n int mod=1e9+7;\n vector<ulli> fact;\n ulli mult(ulli x,ulli y){\n return (x%mod * y%mod)%mod;\n } \n void factorial(ulli x){\n fact[0]=1;\n fact[1]=1;\n for(ulli i=2;i<=x;i++){\n fact...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n int m = sick.size();\n \n int mod = 1000000007;\n \n vector<int> num(n + 1, 0);\n vector<int> denom(n + 1, 0);\n\n findPrimes(n + 1); \n \n int pos = n - m;...
3,224
<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p> <p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process con...
2
{ "code": "class Solution {\npublic:\n int numberOfSequence(int n, vector<int>& sick) {\n const int MOD = 1e9 + 7; // Modulus value for operations\n\n // Initializing vectors and variables\n vector<int> xs; // Vector to store segment lengths without sick indices\n vector<bool> a(n, 0); ...