id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "#define ll long long int \n#define pb push_back\nclass Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n /*Brute Force*/\n int end=1<<n;\n int cnt=0;\n map<pair<ll,ll>,ll> mp;\n for(auto it:roads){\n pair<ll,ll> g...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n const long long inf = 1e15;\n vector<vector<long long>> dist(n, vector<long long>(n, inf));\n\n // Initialize distanc...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n bool check(vector<int>&v,int maxi,vector<vector<int>>& roads,int n)\n {\n if(v.size()==0||v.size()==1)return true;\n vector<vector<int>>grid(n,vector<int>(n,1e9));\n unordered_map<int,int>m;\n for(int i=0;i<v.size();i++)\n {\n m...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\nvector<vector<int>> getMinDist(vector<vector<int>> &roads, unordered_set<int> &st, int n) {\n vector<vector<int>> dist(n, vector<int>(n, INT_MAX));\n for (const auto& road : roads) {\n int u = road[0];\n int v = road[1];\n int w = road[2...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n // 11111\n // 10111\n //\n // 2\n // 0, 1, 2, 3\n // 00 01 10 11\n // 1024 * 100\n // 10^6\n vector<vector<int>> getMinDist(vector<vector<int>> &roads, unordered_set<int> &st, int n) {\n vector<vector<int>> dist(n, vector<int>(n, INT_MAX));\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "\nclass Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n int maxi = (1 << n); // To generate all subsets\n int ans = 0;\n\n for (int z = 0; z < maxi; z++) {\n set<int> st; // Set to store selected branches in current subset\n...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n int maxi = (1 << n); // To generate all subsets\n int ans = 0;\n\n for (int z = 0; z < maxi; z++) {\n set<int> st; // Set to store selected branches in current subset\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n int maxi = (1 << n); // To generate all subsets\n int ans = 0;\n\n for (int z = 0; z < maxi; z++) {\n set<int> st; // Set to store selected branches in current subset\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n //1. try all possible sets. total sets will be 2^n-1\n //set 0 meaning 000, none of the 012 nides/braches are chosen\n //2. now for each subset we make a resuktant graph\n //m...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n // seems like floyd warshall\n int ans = 0 ; \n for (int mask = 0; mask < (1 << n); mask++) {\n vector<vector<int>> dist(n, vector<int>(n, 1e9));\n for (auto i...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
2
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n // we'll be using floy warshell to get the shortest distance from each node to every other node\n\n // using bit manipulation technique to store all the subsequences\n\n int cnt = 0;...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\nprivate:\n int helper(int n, int maxDistance, vector<vector<int>>& roads, int branch) {\n vector<vector<int>> matrix(n, vector<int>(n, 1e9));\n for (auto v : roads) \n {\n if(((1<<v[0])&branch) or ((1<<v[1])&branch)) continue;\n matrix[v[0]][v...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n bool isvalid(const int mask, const int n, const int md, const vector<vector<int>>& rds) {\n vector<vector<int>>w(n, vector<int>(n, 100000000));\n for(int i = 0; i < n; ++i) {\n w[i][i] = 0;\n }\n \n for(auto r : rds) {\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n int ans=0;\n for(int i=0;i<(1LL<<n);i++){\n vector<vector<int>> dist(n+1,vector<int>(n+1,1e8));\n for(auto x : roads){\n if((i&(1<<x[0])) && (i&(1<<x[1]...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\n\n bool wf(vector<vector<int>>& adj,int inf,set<int>& st){\n int n=adj.size();\n\n for(int k=0;k<n;k++){\n for(int i=0;i<n;i++){\n for(int j=0;j<n;j++){\n if(i!=j){\n if(adj[i][k]<inf && adj[k][j]<inf){\n...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int f(int i,int n,vector<vector<int>>mat,set<int>&s,int d){\n if(i==n){\n for(int l=0;l<n;l++){\n if(s.find(l)!=s.end()){\n continue;\n }\n for(int j=0;j<n;j++){\n for(int k=0...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "const int inf = 1e6 ;\nclass Solution {\npublic:\n void dijkstra(int i, vector<pair<int,int>> adj[],vector<int>&dis){\n dis[i] = 0 ;\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; \n pq.push({0,i}) ;\n while(!pq.empty()){\n int ver...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\n bool check(vector<vector<int>>&mat, int dis, map<int,int>&mp){\n \n int n = mat.size();\n// for(int i = 0; i < n; i++){\n// for(int j =0 ; j < n; j++)\n// {\n// cout<<mat[i][j]<<\" \";\n// }\n// cout...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int k, vector<vector<int>>& roads) {\n int ans = 0;\n // check for every possible subset\n for(int i = 0;i < (1 << n);i++){\n unordered_set<int>st;\n for(int j = 0;j < n;j++){\n // inserting the...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int k, vector<vector<int>>& roads) {\n int ans = 0;\n // check for every possible subset\n for(int i = 0;i < (1 << n);i++){\n unordered_set<int>st;\n for(int j = 0;j < n;j++){\n // inserting the...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n int res=0;\n vector<vector<long long>> graph(n, vector<long long>(n, INT_MAX));\n vector<int> notValid(n);\n for(auto& el: roads)\n {\n graph[el[0]][el[1]]=m...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int numberOfSets(int n, int maxDistance, vector<vector<int>>& roads) {\n int res = 0;\n for (int mask = 0; mask < (1 << n); ++mask) {\n unordered_map<int, vector<pair<int, int>>> g;\n set<int> nodes;\n for (auto& road : roads) {\...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<vector<ll>> subs;\n\n void generate(ll lev, vector<ll> vec){\n if(lev==-1){\n subs.push_back(vec);\n return;\n }\n\n vec.push_back(lev);\n generate(lev-1,vec);\n vec.pop_back();...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n vector<vector<ll>> subs;\n\n void generate(ll lev, vector<ll> vec){\n if(lev==-1){\n subs.push_back(vec);\n return;\n }\n\n vec.push_back(lev);\n generate(lev-1,vec);\n vec.pop_back();...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "bool fun1(vector<vector<int>> dp,int m,int maxDistance,int n)\n{\n for(int k=0;k<n;k++)\n {\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<n;j++)\n {\n if((m&(1<<i))&&(m&(1<<j)))\n {\n if(dp[i][k]!=INT_MAX&&dp[k][j]!=INT...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "bool fun1(vector<vector<int>> dp,int m,int maxDistance,int n)\n{\n for(int k=0;k<n;k++)\n {\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<n;j++)\n {\n if((m&(1<<i))&&(m&(1<<j)))\n {\n if(dp[i][k]!=INT_MAX&&dp[k][j]!=INT...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n\n const long long INF = 1e18;\n\n bool floydWarshall(vector<vector<int>> edges, int n, int mask, int maxDistance) {\n vector<vector<long long>> dist(n, vector<long long>(n, INF));\n for (int i = 0; i < n; i++) {\n dist[i][i] = 0;\n }\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n \n vector<vector<int>> helper(vector<vector<int>> &A) { \n int n = A.size(); \n vector<vector<int>> dist = A;\n\n for (int k = 0; k < n; k++) { \n for (int i = 0; i < n; i++) { \n for (int j = 0; j < n; j++) { \n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n bool connected_and_reachable(int n , int mask , vector<vector<int>> dist , int d){\n vector<int> nodes ; \n for(int i = 0 ; i < n ; i++){\n if(mask & (1 << i)){\n nodes.push_back(i) ; // For storing all the nodes in maks\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int ans;\n vector<int> node;\n void check(int n,vector<vector<int>> matrix,int maxDis){\n for(int k=0;k<n;k++){\n if(!node[k]) continue;\n for(int i=0;i<n;i++){\n if(!node[i]) continue;\n for(int j=0;j<n;j++){\n...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n vector<int> dijkstra(vector<vector<pair<int, int>>>& graph, int source) {\n vector<int> dist(graph.size(), 1e9);\n priority_queue<pair<int, int>> pq;\n dist[source] = 0;\n pq.push({0, source});\n while(!pq.empty()) {\n int cur = p...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n bool check(int n, vector<vector<int>> dist, set<int>& inactive, int maxi) {\n for(int i = 0;i < n; i++) {\n if(inactive.find(i) != inactive.end()) {\n for(int j = 0; j < n; j++) {\n dist[i][j] = (int)1e9;\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int check(vector<vector<int>>& g, vector<vector<int>>& dist, int maxDistance, int i){\n int res = 0;\n for(int j = 0; j < 10; ++j){\n if(i & (1 << j)) { \n int nodeCount = 1;\n vector<int> visited(g.size(), 10001);\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int check(vector<vector<int>>& g, vector<vector<int>>& dist, int maxDistance, int i){\n int res = 0;\n for(int j = 0; j < 10; ++j){\n if(i & (1 << j)) { \n int nodeCount = 1;\n vector<int> visited(g.size(), 10001);\n ...
3,217
<p>There is a company with <code>n</code> branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.</p> <p>The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, t...
3
{ "code": "class Solution {\npublic:\n int check(vector<vector<int>>& g, vector<vector<int>>& dist, int maxDistance, int i){\n int res = 0;\n for(int j = 0; j < 10; ++j){\n if(i & (1 << j)) { \n int nodeCount = 1;\n vector<int> visited(g.size(), 10001);\n ...
3,220
<p>You are given a <strong>0-indexed</strong> integer array <code>batteryPercentages</code> having length <code>n</code>, denoting the battery percentages of <code>n</code> <strong>0-indexed</strong> devices.</p> <p>Your task is to test each device <code>i</code> <strong>in order</strong> from <code>0</code> to <code>...
0
{ "code": "class Solution {\npublic:\n int countTestedDevices(vector<int>& batteryPercentages) {\n int count=0;\n for(int i=0;i<batteryPercentages.size();i++){\n if(batteryPercentages[i]>0)\n {\n count++;\n for(int j=i+1;j<batteryPercentages.size();...
3,220
<p>You are given a <strong>0-indexed</strong> integer array <code>batteryPercentages</code> having length <code>n</code>, denoting the battery percentages of <code>n</code> <strong>0-indexed</strong> devices.</p> <p>Your task is to test each device <code>i</code> <strong>in order</strong> from <code>0</code> to <code>...
0
{ "code": "class Solution {\npublic:\n int countTestedDevices(vector<int>& batteryPercentages) {\n int ans = 0, n = batteryPercentages.size();\n for (auto& val: batteryPercentages) {\n if (val - ans > 0) ans++;\n }\n return ans;\n }\n};", "memory": "20400" }
3,220
<p>You are given a <strong>0-indexed</strong> integer array <code>batteryPercentages</code> having length <code>n</code>, denoting the battery percentages of <code>n</code> <strong>0-indexed</strong> devices.</p> <p>Your task is to test each device <code>i</code> <strong>in order</strong> from <code>0</code> to <code>...
0
{ "code": "class Solution {\npublic:\n int countTestedDevices(vector<int>& batteryPercentages) {\n int tested_devices = 0;\n\n int to_decrement = 0;\n\n for (int i = 0; i < batteryPercentages.size(); ++i) {\n if (batteryPercentages[i] - to_decrement > 0) {\n to_decrem...
3,220
<p>You are given a <strong>0-indexed</strong> integer array <code>batteryPercentages</code> having length <code>n</code>, denoting the battery percentages of <code>n</code> <strong>0-indexed</strong> devices.</p> <p>Your task is to test each device <code>i</code> <strong>in order</strong> from <code>0</code> to <code>...
0
{ "code": "class Solution {\npublic:\n int countTestedDevices(vector<int>& batteryPercentages) {\n int count=0;\n for(int i=0;i<batteryPercentages.size();i++){\n if(batteryPercentages[i]>0){\n count++;\n int j=i;\n while(j<batteryPercentages.siz...
3,220
<p>You are given a <strong>0-indexed</strong> integer array <code>batteryPercentages</code> having length <code>n</code>, denoting the battery percentages of <code>n</code> <strong>0-indexed</strong> devices.</p> <p>Your task is to test each device <code>i</code> <strong>in order</strong> from <code>0</code> to <code>...
0
{ "code": "class Solution {\npublic:\n int countTestedDevices(vector<int>& batteryPercentages) {\n int testedDevices=0;\n for(int i=0;i<batteryPercentages.size();i++)\n {\n if(batteryPercentages[i]>testedDevices)\n {\n testedDevices+=1;\n }\n ...
3,234
<p>You are given a <strong>0-indexed</strong> 2D array <code>variables</code> where <code>variables[i] = [a<sub>i</sub>, b<sub>i</sub>, c<sub>i,</sub> m<sub>i</sub>]</code>, and an integer <code>target</code>.</p> <p>An index <code>i</code> is <strong>good</strong> if the following formula holds:</p> <ul> <li><code>...
0
{ "code": "class Solution {\npublic:\nconst long long mod = 3000000007;\n int modpow(long long base, int exp) {\n long long result = 1;\n while (exp) {\n if (exp & 1) {\n result *= base;\n result %= 10;\n }\n base *= base;\n base %= 10;\n exp >>= 1;\n ...
3,234
<p>You are given a <strong>0-indexed</strong> 2D array <code>variables</code> where <code>variables[i] = [a<sub>i</sub>, b<sub>i</sub>, c<sub>i,</sub> m<sub>i</sub>]</code>, and an integer <code>target</code>.</p> <p>An index <code>i</code> is <strong>good</strong> if the following formula holds:</p> <ul> <li><code>...
0
{ "code": "#include <vector>\n#include <cmath> // For pow\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> getGoodIndices(vector<vector<int>>& variables, int target) {\n vector<int> result;\n \n for(int i = 0; i < variables.size(); i++) {\n int a = variables[i][0];\n...
3,234
<p>You are given a <strong>0-indexed</strong> 2D array <code>variables</code> where <code>variables[i] = [a<sub>i</sub>, b<sub>i</sub>, c<sub>i,</sub> m<sub>i</sub>]</code>, and an integer <code>target</code>.</p> <p>An index <code>i</code> is <strong>good</strong> if the following formula holds:</p> <ul> <li><code>...
1
{ "code": "class Solution {\npublic:\n int pmod(int a, int x, int m) {\n long long res = 1;\n while (x) {\n if (x & 1) {\n res = (res * a)%m;\n }\n a = (1LL*a*a)%m;\n x >>= 1;\n }\n return res;\n }\n\n vector<int> getGoodI...
3,234
<p>You are given a <strong>0-indexed</strong> 2D array <code>variables</code> where <code>variables[i] = [a<sub>i</sub>, b<sub>i</sub>, c<sub>i,</sub> m<sub>i</sub>]</code>, and an integer <code>target</code>.</p> <p>An index <code>i</code> is <strong>good</strong> if the following formula holds:</p> <ul> <li><code>...
1
{ "code": "#define mod 100000007\n\nclass Solution {\npublic:\n vector<int> getGoodIndices(vector<vector<int>>& va, int target) {\n vector<int>ans;\n int n = va.size();\n\n for(int i = 0;i<n;i++){\n int a = va[i][0];\n int b= va[i][1];\n int c = va[i][2];\n int m = ...
3,234
<p>You are given a <strong>0-indexed</strong> 2D array <code>variables</code> where <code>variables[i] = [a<sub>i</sub>, b<sub>i</sub>, c<sub>i,</sub> m<sub>i</sub>]</code>, and an integer <code>target</code>.</p> <p>An index <code>i</code> is <strong>good</strong> if the following formula holds:</p> <ul> <li><code>...
2
{ "code": "class Solution {\npublic:\n long long binpow(long long a, long long b, long long m) {\n a %= m;\n long long res = 1;\n while (b > 0) {\n if (b & 1)\n res = res * a % m;\n a = a * a % m;\n b >>= 1;\n }\n return res;\n }...
3,234
<p>You are given a <strong>0-indexed</strong> 2D array <code>variables</code> where <code>variables[i] = [a<sub>i</sub>, b<sub>i</sub>, c<sub>i,</sub> m<sub>i</sub>]</code>, and an integer <code>target</code>.</p> <p>An index <code>i</code> is <strong>good</strong> if the following formula holds:</p> <ul> <li><code>...
3
{ "code": "class Solution {\npublic:\n vector<int> getGoodIndices(vector<vector<int>>& variables, int target) {\n vector<int> res;\n\n for (int i = 0; i < variables.size(); i++){\n auto cur = variables[i];\n\n int one = cur[0];\n int two = cur[1];\n int thr...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int max_freq=0;\n int max_freq_count=1;\n for(int i=0;i<nums.size();i++)\n {\n int freq=0;\n for(int j=i;j<nums.size();j++)\n {\n if(nums[i] == nums[j])...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int cnt[105];\n int maxFrequencyElements(vector<int>& nums) {\n int maxi = 0;\n for(auto a : nums) {\n maxi = max(maxi, ++cnt[a]);\n }\n int ans = 0;\n for(auto a : nums) {\n ans += cnt[a] == maxi;\n }\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int n = nums.size();\n int sumOfFreq=0;\n int ans[n];\n int freq_1 = INT_MIN;\n for( int i=0;i<n;i++){\n int num = nums[i]; int freq=0;\n for( int j=i;j<n;j++){\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n int l =0 ;\n int max = INT_MIN , cn = 0;\n\n for(int i = 0 ; i < nums.size(); i++)\n {\n if(i+1 < nums.size() && nums[i] == nums[i+1]) continue;\n...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n\n sort(nums.begin(), nums.end());\n int maxfreq = INT_MIN;\n\n int c = 1;\n for(int i=1;i<nums.size();i++)\n {\n if(nums[i] == nums[i-1])\n c++;\n else\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int cnt=0;\n int maxi = *max_element(nums.begin(), nums.end());\n vector<int>fre(maxi+1 ,0);\n for( int i=0; i<nums.size(); i++){\n fre[nums[i]]++;\n }\n int freMax = *max_element(fre.b...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& arr) {\n int n=arr.size();\n int max=INT_MIN;\n for(int i=0;i<n;i++){\n if(arr[i]>max){\n max=arr[i];\n }\n }\n vector<int> vec(max+1,0);\n\n for(int i=0;i<n;i...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n vector<int> freq(101);\n for(int num : nums){\n freq[num]++;\n }\n\n int max_freq = freq[0];\n for(int f : freq){\n max_freq = max(f, max_freq);\n }\n\n int ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int n=nums.size();\n vector<int> temp(101, 0); \n int maxi=0,ans=0; \n for(int i=0;i<n;i++){\n temp[nums[i]]++;\n if(temp[nums[i]]>maxi){\n maxi=temp[nums[i]];\n...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int hash[101]={};\n int count{0};\n for(int i =0 ; i<nums.size() ; ++i){\n hash[nums[i]]++;\n }\n int max=hash[0];\n for(auto& it:hash){\n if(it>max){\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n vector<int>vec(101,0);\n for(int i=0;i<nums.size();i++)\n {\n vec[nums[i]]++;\n }\n int maxi=*max_element(vec.begin(),vec.end());\n int count=0;\n for(int i=0;i<vec.siz...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n vector<int> hash(110,0);\n for(int i=0;i<nums.size();i++){\n hash[nums[i]]+=1;\n } \n int max=0;\n for(int i=0;i<hash.size();i++){\n if(max<hash[i]){\n ma...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int j;\n int greatest=INT_MIN;\n int sum=0;\n map<int,int>m;\n sort(nums.begin(),nums.end());\n for(auto i:nums){\n j=count(nums.begin(),nums.end(),i);\n m[i]=j;\n }\n fo...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
0
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n map<int, int> m;\n int maxFreq = 0;\n int FinalFreq = 0;\n\n for(auto& num : nums)\n {\n m[num]++;\n auto freq = m[num];\n\n if (freq > maxFreq)\n {\...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
1
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n map<int, int> mp;\n for(auto num : nums) {\n ++mp[num];\n }\n \n int maxFreq = 0;\n for(const auto& pair : mp) {\n if(pair.second > maxFreq) {\n maxF...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
1
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n unordered_map<int,int>m;\n for(auto&num:nums){\n m[num]++;\n }\n\n int max=-1;\n int ele=-1;\n int verymax=0;\n for(auto&num:m){\n if(num.second>max){\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
1
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n }\n int maxi = INT_MIN;\n \n for(auto x : mp) {\n maxi = max(maxi, x.second);\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
1
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n map<int,int>mp1;\n for(int i:nums)\n {\n mp1[i]++;\n }\n map<int,int>mp2;\n for(auto i:mp1)\n mp2[i.second]++;\n return mp2.rbegin()->first*mp2.rbegin()->secon...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
2
{ "code": "#include <vector>\n#include <unordered_map>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n unordered_map<int,int>freq;\n int maxf;\n \n int sum=0;\n for(auto i:nums)\n {\n fre...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
2
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n int maxFreq = 0;\n int ans = 0;\n unordered_map<int,int> freq;\n for(auto x : nums) freq[x]++;\n\n for(auto y : freq){\n if(y.second > maxFreq) maxFreq = y.second;\n }\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
2
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n unordered_map<int,int> freq;\n int maxFreq=INT_MIN;\n for(auto num : nums)\n {\n if(freq.find(num)!=freq.end())\n {\n auto occ = freq[num];\n occ+=1...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
2
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n unordered_map<int,int>copy;\n for(int x:nums)\n {\n copy[x]++;\n }\n vector<int>freq;\n for(auto x:copy)\n {\n freq.push_back(x.second);\n }\n ...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
3
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) {\n unordered_map<int,int> freq_map;\n for(auto& num : nums)\n freq_map[num]++;\n // 1 = 2\n // 2 = 2\n // 3 = 1\n // 4 = 1\n int maxfreq = INT_MIN;\n for(int i = 0;...
3,242
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p> <p>Return <em>the <strong>total frequencies</strong> of elements in</em><em> </em><code>nums</code>&nbsp;<em>such that those elements all have the <strong>maximum</strong> frequency</em>.</p> <p>The <strong>frequency</st...
3
{ "code": "class Solution {\npublic:\n int maxFrequencyElements(vector<int>& nums) \n {\n unordered_map<int,int>mp;\n int maxi = 0;\n int ans = 0;\n for(int i=0; i<nums.size();i++)\n {\n mp[nums[i]]++;\n maxi = max(maxi, mp[nums[i]]);\n }\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n std::vector<int> beautifulIndices(const std::string& s, const std::string& a, const std::string& b, const int& k) {\n const size_t len_s = s.size(), len_a = a.size(), len_b = b.size();\n std::vector<int> indices;\n\n if(len_a > len_s || len_b > len_s || !s.contains(a) ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> ans;\n int sl = s.length(), al = a.length(), bl = b.length();\n\n int pos = s.find(a);\n while (pos != string::npos) {\n auto pos_j = s.find(b, max(0, int(...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n bool checkValid(int i, const string& s, const string& b, int k) {\n int left = max(0, i - k);\n int n = s.length();\n int right = min(n - 1, i + k);\n\n for (int ind = left; ind <= right; ind++) {\n if (ind + b.length() <= n) {\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\nprivate:\n vector<bool> computeMatches(string& p, string& s){\n const int P_LEN = p.length();\n const int N = s.length();\n\n vector<bool> isMatchingPAt(N);\n for(int i = 0; i + P_LEN - 1 < N; ++i){\n isMatchingPAt[i] = equal(p.begin(), p.end(), s...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> ans;\n vector<int> last2;\n for(int i = 0; i < s.length(); i++) {\n if(s.substr(i,b.length()) == b) {\n last2.push_back(i);\n }\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> result;\n vector<int> b_indices;\n int n = s.size();\n int a_len = a.size();\n int b_len = b.size();\n \n for (int j = 0; j <= n - b_len; ++j) {\...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n = s.size();\n vector<bool> dp_a(n, false);\n vector<bool> dp_b(n, false);\n vector<int> res;\n\n for(int i = 0; i < n; ++i){\n if(s.substr(i, a.size()) ==...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int na = a.size();\n int nb = b.size();\n int n = s.size();\n vector<int> check;\n for(int i = 0;i<=n-nb;i++){\n if(s.substr(i,nb) == b){\n check...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int na = a.size();\n int nb = b.size();\n int n = s.size();\n vector<int> check;\n for(int i = 0;i<=n-nb;i++){\n if(s.substr(i,nb) == b){\n check...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n = s.size(), i = 0, j = 0;\n vector<int> arri, ret;\n while ((i = s.find(a, i)) != -1) {\n arri.push_back(i);\n i++;\n }\n int lt = 0;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> wait;\n vector<int> result;\n string suba;\n string subb;\n int posa=-1000000;\n int posb=-1000000;\n for(int i=0;i<s.length();i++){\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "#include <vector>\n#include <string>\n\nusing std::vector;\nusing std::string;\n\nclass Solution {\npublic:\n // Method to find all 'beautiful' indices where patterns A and B occur within 'k' distance\n vector<int> beautifulIndices(const string& s, const string& patternA, const string& patternB, int ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\nprivate:\n vector<int> computeMatches(string& p, string& s){\n int pLen = p.length();\n int sLen = s.length();\n\n vector<int> matches;\n for(int i = 0; i + pLen - 1 < sLen; ++i){\n if(equal(p.begin(), p.end(), s.begin() + i)){\n ma...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n\n bool checkForWord(string& s, string& toCheckFor, int i) {\n int j = 0;\n while(i < s.size() && j < toCheckFor.size()) {\n if(s[i++] != toCheckFor[j++]) return false;\n }\n return j != toCheckFor.size() ? false : true;\n }\n\n vec...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n = s.size();\n vector<int>va,vb;\n\n for(int i=0;i<n;i++){\n int x=i;\n\n bool flag1 = true, flag2 = true;\n\n for(int j=0;j<a.size();j++){\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n // get queue of Is\n // get queue of Js\n // for each I, pop frontmost J until j >= i - k\n queue<int> Js = getIndices(s, b);\n vector<int> res;\n for (int i = 0; i...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int>computePrefix(string &pattern){\n //we want to find substrings of the string where suffix = prefix \n vector<int>prefix(pattern.size(), 0);\n int j = 0;\n for(int i = 1; i < pattern.size(); i ++){\n while(j > 0 && pattern[j] !...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n\n void construct(string &s,vector<int>&lps)\n {\n int sz=s.size();\n lps[0]=0;\n int length=0;\n int i=1;\n while(i<sz)\n {\n if(s[i]==s[length])\n {\n lps[i++]=++length;\n }\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> generateLPS(string& str) {\n int n = str.size();\n vector<int> LPS(n);\n LPS[0] = 0;\n int len = 0, i = 1;\n while (i < n) {\n if (str[i] == str[len]) {\n LPS[i] = len + 1;\n i++;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
0
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> ans;\n vector<int> positions_a, positions_b;\n int n = s.size();\n\n // Early exit: If 'a' or 'b' cannot fit in 's', return empty result\n if (a.size() > n || ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
1
{ "code": "class Solution {\npublic:\n vector<int> kmpSearch(const string& text, const string& pattern) {\n vector<int> indices;\n vector<int> pi = computePrefixFunction(pattern);\n int q = 0; \n for (int i = 0; i < text.length(); i++) {\n while (q > 0 && pattern[q] != text[i...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
1
{ "code": "class Solution {\n using ll = long long;\n long long base = 101;\n long long mod = 1e9 + 7;\n\n ll calcHash(const string& str, int start, int end) {\n ll hash = 0;\n for (int i = start; i <= end; i++) {\n hash = (hash * base + str[i]) % mod;\n }\n return h...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n // 11:27\n // i[i] to s[i + a.length - 1]\n // where squir\n // where my \n // <4, 18> --> sq\n // <16, 33> --> my\n vector<int> index_i;\n vector<int...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n int n = s.size();\n int m = a.size();\n int z = b.size();\n vector<int> a_idx;\n vector<int> b_idx;\n for(int i=0;i<s.size();i++){\n if(s.substr(i, m)==a...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\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 \npublic:\n vector<int> beautifulIndices(s...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
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> computeMatches(string& p, stri...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> closestB(s.size(), 100001);\n for (int i = 0; i < s.size(); i++) {\n if (i + b.size() <= s.size() && s.substr(i, b.size()) == b) {\n closestB[i] = 0;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> closestB(s.size(), 100001);\n for (int i = 0; i < s.size(); i++) {\n if (i + b.size() <= s.size() && s.substr(i, b.size()) == b) {\n closestB[i] = 0;\n ...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n \n vector<int> ans;\n string t = s;\n vector<int> first;\n vector<int> second;\n if(a.size()>s.size() or b.size()>s.size()) return {};\n\n for(int i=0;i<=s.s...
3,245
<p>You are given a <strong>0-indexed</strong> string <code>s</code>, a string <code>a</code>, a string <code>b</code>, and an integer <code>k</code>.</p> <p>An index <code>i</code> is <strong>beautiful</strong> if:</p> <ul> <li><code>0 &lt;= i &lt;= s.length - a.length</code></li> <li><code>s[i..(i + a.length - 1)]...
2
{ "code": "class Solution {\npublic:\n vector<int> beautifulIndices(string s, string a, string b, int k) {\n vector<int> i_candidates;\n vector<int> j_candidates;\n \n helperFind(i_candidates, s, a);\n helperFind(j_candidates, s, b);\n \n vector<int> ans;\n\n ...