id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
1
{ "code": "class Node{\n public:\n map<pair<char,char>, Node*> map;\n int count;\n\n Node():count(0){}\n};\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n long long ans=0;\n Node * trie = new Node();\n for(auto &word:words){\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Trie{\n public:\n map<pair<int,int>,Trie*> child;\n int cnt;\n\n Trie(){\n cnt=0;\n }\n\n int insert(string word){\n Trie *cur=this;\n int res=0;\n int n=word.size();\n for(int i=0;i<n;i++){\n int id1=word[i]-'a',id2=word[n-1-i]-'a';\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Node{\n public:\n map<pair<char,char>,Node*> links;\n long long count;\n bool flag;\n Node(){\n count=0;\n flag=false;\n }\n bool isPresent(char a,char b){\n return (links.find({a,b})!=links.end());\n }\n void add(char a,char b){\n Node* n1=new N...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "\nclass TrieNode {\n public: \n\t map<pair<char, char>, TrieNode*> children;\n\t bool isEndOfWord;\n long long count;\n TrieNode() {\n children = map<pair<char, char>, TrieNode*>();\n isEndOfWord = false;\n count = 0ll;\n }\n};\n\nclass Trie {\...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n ll const p=31,mod=1e9+7;\n long long countPrefixSuffixPairs(vector<string>& words) {\n ll ans=0;\n unordered_map<ll,ll> m;\n \n for(auto &s:words){\n unordered_set<ll> st;\n ll hash=0,power=1;\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n ll const p=31,mod=1e9+7;\n ll prefixHash(string s){\n ll hash=0,power=1;\n for(int i=0;i<s.size();i++){\n hash+=((s[i]-'a' )+1)*power;\n hash%=mod;\n power*=p;\n power%=mod;\n }\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "struct Trie{\n map<pair<int,int>, Trie*>mp;\n int count;\n Trie(){\n count=0;\n }\n};\nclass Solution {\npublic:\n void insert(string key, Trie* root){\n int n = key.length();\n for(int k=0;k<n;k++){\n int i = key[k]-'a';\n int j = key[n-k-1]-'a';\n...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "#define ll long long int \n#define pb push_back\nclass Solution {\npublic:\nll pow31[100001];\nll N=1e9+7;\n long long countPrefixSuffixPairs(vector<string>& words) {\n /*String Hashing+ MAP*/\n ll gt=1;\n for(int i=0;i<100001;i++){\n pow31[i]=gt;\n gt=(gt*31)%...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n unordered_map<string, int> st;\n long long ans = 0;\n for(int i=0; i<words.size(); i++){\n \n int n = words[i].length();\n string a = \"\";\n map<int, ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "#define lli long long int\nclass Solution {\npublic:\n const lli x = 169;\n const lli N = (lli)1e5;\n const lli mod = 222222222222222221;\n\n lli mul(lli a, lli b) {\n return ((__int128)a * b) % mod;\n }\n\n lli countPrefixSuffixPairs(vector<string>& v) {\n vector<lli> pw(N ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "#define lli long long int\nclass Solution {\npublic:\n const lli x = 169;\n const lli N = (lli)1e5;\n const lli mod = 222222222222222221LL;\n\n lli mul(lli a, lli b) {\n return ((__int128)a * b) % mod;\n }\n\n lli countPrefixSuffixPairs(vector<string>& v) {\n vector<lli> pw(...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "#define lli long long int\nconst lli N = 1e5;\nconst lli x[2] = {169, 269};\nconst lli m[2] = {1103855923, 110385623};\n\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& v) {\n vector pw(2, vector<lli>(N + 1, 1));\n for (lli i = 0; i < 2; i++)\n for ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll=long long;\nconst ll B = 31;\nconst ll md = 1e9 + 9;\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n vector<ll> pB(100005);\n pB[0] = 1ll;\n for (int i = 1; i < 100001; i++) pB[i] = (pB[i-1] * B) % md;\n ll ans=0;\n ma...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll=long long;\nconst ll B = 31;\nconst ll md = 1e9 + 9;\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n vector<ll> pB(100005);\n pB[0] = 1ll;\n for (int i = 1; i < 100001; i++) pB[i] = (pB[i-1] * B) % md;\n ll ans=0;\n ma...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "#include<bits/stdc++.h>\ntypedef long long ll;\n \n#define rep(i,a,b) for(ll i=a;i<b;i++)\n#define revrep(i,a,b) for(ll i=a;i>=b;i--)\n#define yes cout << \"YES\" << endl;\n#define no cout << \"NO\" << endl;\n#define vi vector<ll>\n#define pb push_back\n#define fast_cin() ios_base::sync_with_stdio(false); ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\n\nclass Solution {\npublic:\n static const ll A = 96420;\n static const ll B = 1e9+7;\n\n long long countPrefixSuffixPairs(vector<string>& words) {\n vector<ll> p(500001);\n p[0] = 1;\n for(ll i=1; i<=5e5; i++){\n p[i] = (p[i-1]*A)%B;\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& a) {\n unordered_map<int,int>mp;\n unordered_map<int,int>mm;\n int p=31,m=1e9+7;\n long long ans=0;\n vector<long long>pow(100001,1);\n for(int i=1;i<=100000;i++) pow[i]=(pow[i-1]*p)%m;...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n int64_t ans = 0;\n struct Trie {\n std::map<std::pair<char,char>,int> next;\n int64_t count = 0;\n int64_t end;\n };\n std::vector<Trie> t;\n t.push...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\nint f[100001] = { 0 };\nchar PandS[100001];\n// int children[500001][26];\n\n\nstruct Trie {\n vector<array<int, 26>> children;\n vector<int> count;\n Trie() { makeNode(); }\n ll query(const string &word) {\n ll ans = 0;\n int idx = 0, cnt = 0;\n for ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\nint f[100001] = { 0 };\nchar PandS[100001];\n// int children[500001][26];\n\n\nstruct Trie {\n vector<array<int, 26>> children;\n vector<int> count;\n Trie() { makeNode(); }\n ll query(const string &word) {\n ll ans = 0;\n int idx = 0, cnt = 0;\n for ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\nint f[100001] = { 0 };\nchar PandS[100001];\n\nstruct Trie {\n vector<array<int, 26>> children;\n vector<ll> count;\n Trie() { makeNode(); }\n // void insert(const string &word) {\n // int idx = 0;\n // for (auto c: word) {\n // auto cidx = c - 'a...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\nint f[100001] = { 0 };\nchar PandS[100001];\n\nstruct Trie {\n vector<array<int, 26>> children;\n vector<ll> count;\n Trie() { makeNode(); }\n void insert(const string &word) {\n int idx = 0, cnt = 0;\n for (auto c: word) {\n auto cidx = c - 'a';\...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\nint f[100001] = { 0 };\nint PandS[100001] = { 0 };\n\nstruct Trie {\n vector<array<int, 26>> children;\n vector<ll> count;\n Trie() { makeNode(); }\n void insert(const string &word, int *f) {\n int idx = 0, cnt = 0;\n for (auto c: word) {\n auto c...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "using ll = long long;\nint f[100001] = { 0 };\nint PandS[100001] = { 0 };\n\nstruct Trie {\n vector<array<int, 26>> children;\n vector<ll> count;\n Trie() { makeNode(); }\n void insert(const string &word, int *f) {\n int idx = 0, cnt = 0;\n for (auto c: word) {\n auto c...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "struct tnode {\n int cnt;\n array<int, 26> nx;\n\n tnode() {\n cnt = 0;\n fill(nx.begin(), nx.end(), -1);\n }\n};\n\nvector<int> get_z(string const &w)\n{\n int n = w.size();\n vector<int> z(n, 0);\n int best = 0;\n\n for (int i = 1; i < n; i++)\n {\n z[i] = ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "struct tnode {\n int cnt;\n array<int, 26> nx;\n\n tnode() {\n cnt = 0;\n fill(nx.begin(), nx.end(), -1);\n }\n};\n\nvector<int> get_z(string w)\n{\n int n = w.size();\n vector<int> z(n, 0);\n int best = 0;\n\n for (int i = 1; i < n; i++)\n {\n z[i] = max(0, ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "struct TrieNode{\n string val;\n \n map<string, TrieNode*> children;\n //unordered_map<string, TrieNode*> children;\n bool isWordEnd;\n int wordEndCount;\n TrieNode(): isWordEnd(false), wordEndCount(0) {};\n TrieNode(string value, bool WordEnd = false ): val(value), isWordEnd(Wor...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\npublic:\n int mx ;\n vector<long long> rolling_hash(string s, map<int, int> &ln) {\n const int p = 31; \n const int m = 1e9 + 9;\n int S = s.size();\n\n vector<long long> p_pow(S); \n p_pow[0] = 1; \n for (int i = 1; i < (int)p_pow.size(); i...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "struct TrieTree {\n array<TrieTree*, 26> children{};\n string_view total;\n int count{0};\n TrieTree(const string_view& s) : total{s} {}\n\n static void insert(TrieTree* node, const string_view& word) {\n for (int i = 0; i < word.size(); ++i) {\n auto& next = node->children...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "struct TrieNode {\n unordered_map<int, TrieNode*> children;\n int count = 0;\n};\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n long long res = 0;\n TrieNode* root = new TrieNode{};\n for(const auto& w : words) {\n TrieNode*...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\npublic:\n struct node{\n unordered_map<int, node*> child;\n int cnt=0;\n };\n class trie{\n public:\n node* root;\n trie(){\n root=new node();\n }\n void insert(string &a){\n node* temp=root;\n int ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\n struct Node {\n unordered_map<int, Node*> child;\n int endOfWord = 0;\n\n bool containsKey(int idx) { return child[idx] != NULL; }\n\n Node* getKey(int idx) { return child[idx]; }\n void setKey(int idx, Node* node) { child[idx] = node; }\n\n v...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Solution {\n struct Node {\n unordered_map<int, Node*> child;\n int endOfWord = 0;\n\n bool containsKey(int idx) { return child[idx] != NULL; }\n void setKey(int idx, Node* node) { child[idx] = node; }\n Node* getKey(int idx) { return child[idx]; }\n void ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "//constrint dekh lena n*s chal jayege \n\nclass Trie{\n public:\n unordered_map<int,Trie*>um;\n int ct;\n\n Trie(){\n ct=0;\n }\n};\n#define ll long long\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n Trie* root=new Trie();\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
2
{ "code": "class Node{\npublic:\n int count;\n unordered_map<int, Node*> children;\n Node(){\n count = 0;\n }\n};\nclass Solution {\npublic:\nusing ll = long long;\n Node* root;\n Solution(){\n root = new Node();\n }\n\n long long countPrefixSuffixPairs(vector<string>& a) {\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "typedef struct Trie {\n unordered_map<int, Trie*> child;\n int cnt;\n\n Trie() {\n this->cnt = 0;\n }\n} Trie;\n\nclass Solution {\n Trie *root;\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n long long ret = 0;\n root = new Trie();\n \n#...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Node{\n private:\n unordered_map<int, Node*> links;\n int endCount;\n\n public:\n Node(){\n endCount = 0;\n }\n // node = hash value\n bool containsKey(int hash){\n return links.find(hash) != links.end();\n }\n\n void...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n struct node {\n unordered_map<int, node*> child;\n int count = 0;\n };\n class Trie {\n public:\n node* root;\n Trie() {\n root = new node();\n }\n\n void insert(string s) {\n node* cur = root;\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Node {\npublic:\n unordered_map<int, Node*> children;\n long long cnt;\n\n Node() {\n cnt = 0;\n }\n};\n\nclass Trie {\npublic:\n Node* root;\n\n Trie() {\n root = new Node();\n }\n\n long long insertAndCount(string s) {\n Node* cur = root;\n long l...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "struct node{\n int val;\n int cnt;\n unordered_map<int,node*>ch;\n};\nclass Solution {\npublic:\n class trie{\n node* getnode(int v){\n node* temp=new node;\n temp->val=v;\n temp->cnt=0;\n return temp;\n }\n node* root;\n p...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n \n class Node{\n public:\n Node* next[26];\n int word_end=0;\n Node()\n {\n for(int i=0;i<26;i++)\n next[i]=NULL;\n }\n };\n \n void addword(string s, Node* root)\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n \n class Node{\n public:\n Node* next[26];\n int word_end=0;\n Node()\n {\n for(int i=0;i<26;i++)\n next[i]=NULL;\n }\n };\n \n void addword(string s, Node* root)\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class TrieNode\n{public:\n int end;\n map<int,TrieNode*> nex;\n TrieNode(){\n end=0;\n } \n};\n\nclass Solution {\npublic:\n TrieNode* root=NULL;\n int updatetrie(TrieNode* rt,string &s)\n { \n auto p=rt;\n int n=s.size();\n for(int i=0;i<s.size();i++)\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Trie{\n public:\n unordered_map<char,Trie*>child;\n long long cnt;\n Trie(){\n cnt=0;\n }\n};\nclass Solution {\npublic:\n int base=31;\n int mod=1e9+7;\n vector<long long> hash;\n vector<long long> powerlist;\n void computePrefixHashes(string& s) {\n int n...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Trie{\n public:\n unordered_map<char,Trie*>child;\n long long cnt;\n Trie(){\n cnt=0;\n }\n};\nclass Solution {\npublic:\n int base=31;\n int mod=1e9+7;\n vector<long long> hash;\n vector<long long> powerlist;\n void computePrefixHashes(string& s) {\n int n...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "struct node{\n int cnt;\n map<char, node*> child;\n node() {\n cnt = 0;\n }\n};\n\nstruct trie{\n node* root;\n trie() {\n root = new node();\n }\n void insert(string& s) {\n node* cur = root;\n cur->cnt++;\n for(auto& c : s) {\n if(cur-...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class PrefixTreeNode {\npublic:\n PrefixTreeNode() {\n for(int i = 0; i < 26; i++) {\n children[i] = NULL;\n }\n isWord = false;\n wordCount = 0;\n }\n\n PrefixTreeNode * children[26];\n bool isWord;\n string word;\n long long wordCount;\n\n int a...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class PrefixTreeNode {\npublic:\n PrefixTreeNode() {\n for(int i = 0; i < 26; i++) {\n children[i] = NULL;\n }\n isWord = false;\n wordCount = 0;\n }\n\n PrefixTreeNode * children[26];\n bool isWord;\n string word;\n long long wordCount;\n\n int a...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n \n using ll = long long;\n \n class TrieNode{\n public:\n \n bool isEnd;\n int cnt;\n TrieNode* children[26];\n \n TrieNode(){\n isEnd = false;\n cnt=0;\n for(int i=0; i<26; i++){\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n const int MARK = -2;\n\n struct Node {\n int cnt = 0;\n Node* child[26] = {nullptr};\n };\n\n long long insert(Node* root, const string & s) {\n int m = s.length();\n // First build nxt array in KMP\n vector<int> nxt(m, -1);\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "// Time: O(n * l)\n// Space: O(t)\n\n// trie\nclass Solution {\nprivate:\n class Trie {\n public:\n Trie()\n : nodes_() {\n new_node();\n }\n\n int add(const string& w) {\n int result = 0, curr = 0;\n for (int i = 0; i < size(w); ++i) {...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class node{\n public:\n int valid;\n int cnt;\n node* next[26];\n node(){\n valid=0;\n cnt=0;\n for(int i=0;i<26;i++){\n next[i]=NULL;\n }\n }\n};\nclass Trie{\n public:\n node* trie;\n Trie(){\n trie=new node;\n }\n vector<int>...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class node{\n public:\n int valid;\n int cnt;\n node* next[26];\n node(){\n valid=0;\n cnt=0;\n for(int i=0;i<26;i++){\n next[i]=NULL;\n }\n }\n};\nclass Trie{\n public:\n node* trie;\n Trie(){\n trie=new node;\n }\n vector<int>...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class node{\n public:\n int valid;\n int cnt;\n node* next[26];\n node(){\n valid=0;\n cnt=0;\n for(int i=0;i<26;i++){\n next[i]=NULL;\n }\n }\n};\nclass Trie{\n public:\n node* trie;\n Trie(){\n trie=new node;\n }\n vector<int>...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class TrieNode {\npublic: \n unordered_map<string, TrieNode*> child; \n int count = 0; \n ~TrieNode() = default;\n};\n\nclass Solution {\npublic:\n long long countPrefixSuffixPairs(vector<string>& words) {\n long long ans = 0; \n TrieNode* trie = new TrieNode(); \n for (aut...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n struct TrieNode {\n long long t; unordered_map<string, TrieNode*> adj;\n TrieNode() {\n t = 0;\n }\n };\n TrieNode* root = new TrieNode();\n void insert(string& word) {\n auto v = root;\n long long n = word.size();\n ...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "/*\ntypedef long long int ll;\n\nconst int N = 1e5+5;\n\nconst int P = 37;\nconst int M = 1e9+7;\n\n#define pii pair<int, int>\n#define F first\n#define S second\n\nll p_pwr[N];\nll prefix_hash[N];\n\nclass Solution {\n unordered_map<int, multiset<int>> hash_per_len;\n \npublic:\n long long countP...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Node{\npublic : \n char val;\n unordered_map<char,Node*> m;\n int count ;\n Node(char value){\n val = value;\n count =0;\n }\n};\n\nclass Trie {\n Node *root ;\npublic: \n Trie(){\n root = new Node('\\0');\n }\n int insert(string &a,vector<int> &preSufIn...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "#define pb push_back\n#define ppb pop_back\n#define pf push_front\n#define ppf pop_front\n#define lb lower_bound\n#define ub upper_bound\n#define all(x) (x).begin(),(x).end()\n#define uniq(v) (v).er...
3,305
<p>You are given a <strong>0-indexed</strong> string array <code>words</code>.</p> <p>Let&#39;s define a <strong>boolean</strong> function <code>isPrefixAndSuffix</code> that takes two strings, <code>str1</code> and <code>str2</code>:</p> <ul> <li><code>isPrefixAndSuffix(str1, str2)</code> returns <code>true</code> ...
3
{ "code": "class Solution {\npublic:\n class Trie {\n public:\n unordered_map<string, std::unique_ptr<Trie>> children;\n int wordCount = 0;\n Trie* insertIfNotPresent(const char c1, const char c2) {\n const string key{c1, c2};\n if (children.find(key) == children.end()...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) \n {\n for(int i=0;i<nums.size();i++)\n {\n int c=0;\n for(int j=0;j<nums.size();j++)\n {\n if(nums[i]==nums[j])\n {\n c++;\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n bool ans = true;\n for(int i = 0; i < nums.size() - 1; i++) {\n int count = 0;\n for(int j = i+1; j < nums.size(); j++) {\n if(nums[i] == nums[j]) {\n \n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n for(int i=0; i<nums.size()-2; i++){\n if(nums[i]==nums[i+2]) return false;\n }\n return true;\n }\n};", "memory": "23800" }
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n for(int i=0;i<nums.size()-1;i++){\n int count=1;\n for(int j=i+1;j<nums.size();j++){\n if(nums[i]==nums[j]) count++;\n }\n if(count>2) return false;\n }\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n for(int i = 1; i< nums.size()-1; i++){\n if(nums[i] == nums[i-1] && nums[i] == nums[i+1]) return false;\n }\n\n return true;\n }\n};", "memory": "239...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n for(int i = 0; i < nums.size() - 2; i++) {\n if(nums[i] == nums[i+2]) return false;\n }\n\n return true;\n }\n};", "memory": "24000" }
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n\n for (int i = 0; i < nums.size() - 2; ++i) {\n if (nums[i] == nums[i+1] && nums[i] == nums[i+2]) {\n return false;\n }\n }\n\n ret...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n std::vector<int> vec(101, 0);\n\n for (auto& x : nums)\n {\n vec[x]++;\n }\n\n int dist{};\n\n for (auto& x : vec)\n {\n if (x > 2) return false;\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n bool ans;\n\n bool a;\n a = false;\n\n int arr[101] = {0};\n\n int count;\n count = 0;\n\n int i;\n for (i=0;i<=(nums.size () -1);i++) {\n arr[nums[i]]++;\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int n=nums.size()/2;\n vector<int>v(101,0);\n for(int i=0;i<nums.size();++i)\n {\n v[nums[i]]++;\n }\n for(int i=0;i<v.size();++i)\n {\n if(v[i]>2)\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int arr [101] = {0};\n\n for(int& number : nums){\n arr[number]++;\n if(arr[number] > 2) return false;\n } \n\n return true;\n }\n};", "memory": "24400" }
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
0
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n sort(nums.begin() , nums.end());\n int count = 0;\n int n = nums.size();\n if(n % 2 != 0) return false;\n\n int hash[101] = {0};\n for(int i = 0; i<n; i++){\n hash[nums[i]]++;\n...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n vector<int> temp1;\n vector<int> temp2;\n sort(nums.begin(),nums.end());\n int i=0;\n while(i<nums.size()){\n temp1.push_back(nums[i++]);\n temp2.push_back(nums[i++]);\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n vector<int>answer;\n vector<int>answer1;\n sort(nums.begin(), nums.end());\n // unordered_map<int, int>unmap;\n // for(int i=0;i<nums.size();i++)\n // {\n // ++unmap[nums[i]];\n...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& a) {\n int count=0;\n vector<long long>m(101);\n for(auto it:a) m[it]++;\n for(auto it:a)\n {\n if(m[it]>=3) return 0;\n }\n \n return 1;\n }\n};", "memory": "24700" }
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n vector<int>v(200,0);\n for(auto i=nums.begin();i!=nums.end();i++)\n {\n v[*(i)]++;\n if(v[*(i)]>2)\n return false;\n }\n return true;\n }\n};", "memory":...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n ios_base::sync_with_stdio(false);\n\t cin.tie(NULL);\n \n int a[105] = {0};\n int n = nums.size();\n for(int i=0; i<n; ++i){\n a[nums[i]]++;\n if(a[nums[i]]>2) return fal...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n map<int,int> mp;\n for(int i : nums){\n mp[i]++;\n if(mp[i] > 2){\n return false;\n }\n }\n return true;\n }\n};", "memory": "25000" }
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n map <int, int> map;\n for(auto i : nums){\n map[i]++;\n }\n for(auto it: map){\n if(it.second > 2){\n return false;\n }\n }\n return true;\n...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n map<int, int> m;\n for (int i =0; i<nums.size(); i++) {\n m[nums[i]]++;\n if (m[nums[i]] > 2) {\n return false;\n }\n }\n return true;\n }\n};", "mem...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int prev=nums[0];\n map<int, int> mpp;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]+=1;\n }\n for(int i=0;i<nums.size();i++){\n if(mpp[nums[i]]>2){\n retu...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n map<int, int> mpp;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]+=1;\n if(mpp[nums[i]]>2){\n return false;\n }\n }\n return true;\n }\n};", "memor...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int n = nums.size();\n if(n&1) return false;\n map<int , int> mpp;\n for(int i=0 ; i<n ; i++){\n mpp[nums[i]]++;\n }\n for(auto it : mpp){\n if(it.second > 2){\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i=0; i<nums.size(); i++){\n if( mp.find(nums[i]) != mp.end()){\n mp[nums[i]]++;\n }\n else{\n mp[nums[i]]=1;\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
1
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n map<int, int> mpp;\n for(int i=0;i<nums.size();i++){\n mpp[nums[i]]+=1;\n }\n for(int i=0;i<nums.size();i++){\n if(mpp[nums[i]]>2){\n return false;\n }\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
2
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i=0; i<nums.size(); i++){\n if( mp.find(nums[i]) != mp.end()){\n mp[nums[i]]++;\n }\n else{\n mp[nums[i]]=1;\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
2
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int,int> mpp;\n for (int i=0; i<n;i++) {\n mpp[nums[i]]++;\n } \n for (auto &ele : mpp) {\n if (ele.second > 2) return false;\n }...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
2
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n if(mp[nums[i]]>2)\n return false;\n }\n return true;\n }\n};", "memory": "25600" }
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
2
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int,int> mpp;\n \n for(int i = 0; i < nums.size(); i++)\n {\n mpp[nums[i]]++;\n if(mpp[nums[i]]>2)\n return false;\n }\n return true;\n\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
2
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n unordered_map<int,int> mpp;\n \n for(int i = 0; i < nums.size(); i++)\n {\n mpp[nums[i]]++;\n if(mpp[nums[i]]>2)\n return false;\n }\n return true;\n\n ...
3,324
<p>You are given an integer array <code>nums</code> of <strong>even</strong> length. You have to split the array into two parts <code>nums1</code> and <code>nums2</code> such that:</p> <ul> <li><code>nums1.length == nums2.length == nums.length / 2</code>.</li> <li><code>nums1</code> should contain <strong>distinct <...
3
{ "code": "class Solution {\npublic:\n bool isPossibleToSplit(vector<int>& nums) {\n int size = nums.size();\n unordered_map<int,int>mpp;\n for(int i=0;i<size;i++)\n {\n mpp[nums[i]]++;\n if(mpp[nums[i]] > 2)\n return false;\n }\n retur...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
0
{ "code": "class Solution {\npublic:\n long long calculateLargestSquareArea(int x1_1, int y1_1, int x2_1, int y2_1, \n int x1_2, int y1_2, int x2_2, int y2_2) {\n // Find the width and height of the overlap rectangle\n int x_overlap = max(0, min(x2_1, x2_2) - max(x1_1, x1_...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
0
{ "code": "class Solution {\npublic:\n long long largestSquareArea(vector<vector<int>>& bottomLeft, vector<vector<int>>& topRight) {\n int n = bottomLeft.size();\n long long maxSide = 0;\n\n for (int i = 0; i < n; ++i) {\n for (int j = i + 1; j < n; ++j) {\n int left ...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
0
{ "code": "class Solution {\npublic:\n long long largestSquareArea(vector<vector<int>>& bottomLeft, vector<vector<int>>& topRight) {\n long long res = INT_MIN;\n int n = bottomLeft.size();\n for(int i = 0;i < n;i++){\n for(int j = i+1;j < n;j++){\n pair<int,int> l1 = ...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
0
{ "code": "class Solution {\npublic:\n long long largestSquareArea(vector<vector<int>>& nums, vector<vector<int>>& num) {\n long long ans=0;\n for(int i=0;i<nums.size();++i)\n {\n for(int j=i+1;j<num.size();++j)\n {\n int x=max(nums[i][0],nums[j][0]);\n ...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
0
{ "code": "class Solution {\npublic:\n long long largestSquareArea(vector<vector<int>>& left, vector<vector<int>>& right) {\n int n=left.size();\n vector<vector<int>> temp;\n long ans=0;\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n int a=max(left[i][0],l...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
2
{ "code": "class Solution {\npublic:\n long long largestSquareArea(vector<vector<int>>& b, vector<vector<int>>& t) {\n // vector<vector<long long>> v(b.size(), vector<long long>(4));\n // for(int i=0;i<b.size();i++){\n // // v[i][0] = b[0];\n // // v[i][1] = b[1];\n // ...
3,325
<p>There exist <code>n</code> rectangles in a 2D plane with edges parallel to the x and y axis. You are given two 2D integer arrays&nbsp;<code>bottomLeft</code> and <code>topRight</code>&nbsp;where <code>bottomLeft[i] = [a_i, b_i]</code> and <code>topRight[i] = [c_i, d_i]</code> represent&nbsp;the <strong>bottom-left</...
2
{ "code": "class Solution {\npublic:\n long long largestSquareArea(vector<vector<int>>& nums1, vector<vector<int>>& nums2) {\n long long area=0;\n for(int i=0;i<nums1.size();i++){\n for(int j=i+1;j<nums1.size();j++){\n long long minimum_x = max(nums1[i][0], nums1[j][0]);\n ...
3,292
<p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p> <p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>...
0
{ "code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& vi) {\n int ans=0,n=nums.size(),m=vi.size(),i,j;\n for(i=0;i<m;i++){\n if(n<=i+1){\n int vis[n+1],mark[m+1],count=0,ans=0,flag=0;\n memset(vis,0,sizeof(vis))...
3,292
<p>You are given two <strong>1-indexed</strong> integer arrays, <code>nums</code> and, <code>changeIndices</code>, having lengths <code>n</code> and <code>m</code>, respectively.</p> <p>Initially, all indices in <code>nums</code> are unmarked. Your task is to mark <strong>all</strong> indices in <code>nums</code>.</p>...
0
{ "code": "class Solution {\npublic:\n int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n long long l = 0;\n for(auto& num:nums) l += num+1;\n int r = changeIndices.size();\n int res = -1;\n while(l<=r){\n int mid = l+(r-l)/2;\n ...