id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
1
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(const vector<string>& arr) {\n const int n = (int)arr.size();\n unordered_map<string, int> mp;\n vector<unordered_set<string>> subs(n);\n for (int i = 0; i < n; i++) {\n const auto &s = arr[i];\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
1
{ "code": "class Solution {\npublic:\n vector<string> generateSubstring(string& str) {\n vector<string> res;\n for (int len = 1; len <= str.size(); len++) {\n vector<string> temp;\n for (int i = 0; i < str.size(); i++) {\n int j = i+len-1;\n if (j >...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<int, set<string>> mp;\n int n = arr.size();\n for(int i=0; i<n; i++){\n int m = arr[i].size();\n for(int j=0; j<m; j++){\n for(int k=j; k<m; k++)...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n vector<set<string>> substringMap;\n for(auto str: arr){\n set<string> substringsSet;\n for(int i=0;i<str.size();i++){\n string currentSubstr=\"\";\n fo...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n = size(arr);\n vector<string> ans(n);\n vector<vector<string>> subStr(n);\n unordered_map<string, int> dic;\n \n for(int i = 0; i < n; ++i) {\n for(int j = 0;...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "struct TrieNode {\n unordered_map<char, TrieNode*> children; // 存储子节点\n int num; // 标记是否为单词的结尾\n\n TrieNode() : num(0) {} // 初始化 isEndOfWord 为 false\n};\n\nclass Trie {\nprivate:\n TrieNode* root; // Trie 的根节点\n\npublic:\n // 构造函数,初始化 Trie 的根节点\n Trie() {\n root = new TrieNode(...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n \n // static bool mycmp(string s1,string s2){\n // if(s1.length()==s2.length()){\n // return s1<s2;\n // }\n // return s1.length()<s2.length();\n // }\n \n vector<string> shortestSubstrings(vector<string>& arr) {\n \n // ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string, int> m;\n vector<string> ans1;\n\n // Step 1: Count occurrences of each substring across all strings\n for (const auto& val : arr) {\n int t = val.size();\n...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string,int> counts;\n vector<unordered_map<string,int>> counts_vec(arr.size());\n for (int k = 0; k < arr.size(); k++) {\n string a = arr[k];\n int l = a.length...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class node {\npublic:\n node* next[26] = {};\n int cnt = 0;\n bool isEnd = false;\n \n};\n\nclass Trie {\npublic:\n node *root;\n Trie(){\n root = new node();\n }\n void insert_helper(string s){\n node *cur = root;\n for (char c : s){\n int idx = c - ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\n struct Node\n {\n char c;\n bitset<101> b;\n int children[26] = {0};\n };\n\npublic:\n vector<string> shortestSubstrings(const vector<string>& arr)\n {\n vector<Node> nodes;\n nodes.push_back(Node{'\\0'});\n\n int n = arr.size();\n...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n class Node \n {\n public:\n Node* child[26];\n int cnt = 0;\n };\n void Add(Node *head, string s, int index)\n {\n Node *cur = head;\n for ( int i = index; i < s.size() ;i++)\n {\n int c = s[i]-'a';\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n class Node \n {\n public:\n Node* child[26];\n int cnt = 0;\n };\n void Add(Node *head, string s, int index)\n {\n Node *cur = head;\n for ( int i = index; i < s.size() ;i++)\n {\n int c = s[i]-'a';\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n \n struct TrieNode{\n vector<TrieNode *> vec;\n int cnt = 0;\n TrieNode() {\n vec.resize(26);\n }\n };\n \n \n void add(TrieNode * root, string & str, int idx) {\n for (int i = idx; i < str.size(); i++) {\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string,int> m;\n unordered_map<string,int> m2;\n int n=arr.size();\n for(int i=0;i<n;i++)\n {\n int m_=arr[i].size();\n for(int j=0;j<m_;j++)\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n bool isUncommon(vector<string>& arr, string& s, int idx) {\n for (int i = 0; i < arr.size(); i++) {\n if (i != idx) {\n for (int j = 0; j < arr[i].size(); j++) {\n string cur;\n for (int k = j; k < arr[i]....
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n static bool cmp(string &s1,string &s2){\n if(s1.length()==s2.length()){\n return s1<s2;\n }\n return s1.length()<s2.length();\n }\n\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<int,unordered_set<string...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n map<string,set<int>>mp;\n for(int k=0;k<arr.size();k++){\n string str=arr[k];\n for(int i=0;i<str.size();i++){\n string temp=\"\";\n for(int j=i;j<str....
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n = arr.size();\n vector<string> out(n, \"\");\n unordered_map<string, int> store;\n vector<vector<string>> temp(n);\n\n for (int i = 0; i < n; i++) {\n unordered_set<...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": " bool compare(const string& s1, const string& s2) {\n if (s1.size() < s2.size()) {\n return true; \n } else if (s1.size() > s2.size()) {\n return false; \n } else {\n return s1 < s2; \n }\n }\nclass Solution {\npublic:\n vector<string> sho...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
2
{ "code": "class Solution {\npublic:\n static bool cmp(string&a, string&b)\n {\n if(a.size()!=b.size()){\n return a.size()<b.size();\n }\n return a<b;\n \n }\n vector<string> shortestSubstrings(vector<string>& a) {\n vector<string> ans;\n map<string,int...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n //aacha brute force\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string,int> allSubstrings;\n vector<unordered_set<string>> substrings;\n //precomputing all substrings and storing them\n for(auto& s:arr){\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& a) {\n int n = a.size();\n unordered_map<string, int> mp;\n for(string& s : a) {\n int m = s.size();\n for(int i=0; i<m; i++) {\n for(int j=1; j<=m-i; j++) {\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n map<string,int>dic;\n for(auto iter: arr)\n {\n map<string,bool>special;\n for(int i=1;i<=iter.length();i++){\n for(int j=0;j<iter.length();j++){\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n=arr.size();\n map<string,int>mp;\n \n for(int i=0;i<n;i++){\n for(int j=0;j<arr[i].length();j++){\n string temp;\n for(int k=j;k<arr[i].length...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n map<pair<int,string>,int> mpp; \n\n for(const auto& str: arr){\n for(int i = 0; i < str.size(); i++){\n string temp = \"\";\n for(int j = i; j < str.size(); j++){...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n \n struct cmp {\n bool operator()(const string &x, const string &y) const { return x.size()==y.size() ? x < y : x.size() < y.size(); }\n };\n \n using SET = set<string, cmp>;\n \n vector<string> shortestSubstrings(vector<string>& arr) {\n map<s...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n vector<string> out;\n unordered_map<string,int> mp;\n for(auto s:arr){\n int l = s.size();\n unordered_map<string,int>mp1;\n for(int i = 0; i < l; ++i){\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string, int> mp;\n for (auto s : arr) {\n int len = s.length();\n for (int i = 0; i < len; i++) {\n for (int j = i; j < len; j++) {\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "bool cmp(const string & a,const string &b){\n if(a.size()!=b.size())return a.size()<b.size();\n return a<b;\n}\nclass Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n map<string ,int >mp;\n int n=arr.size();\n vector<vector<string>>vec(n);\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(const string & a,const string &b){\n if(a.size()!=b.size())return a.size()<b.size();\n return a<b;\n}\n vector<string> shortestSubstrings(vector<string>& arr) {\n map<string ,int >mp;\n int n=arr.size();\n vector<vector<string>>vec(n)...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n bool compareStrings(const string& s1, const string& s2) {\n if (s1.size() < s2.size()) {\n return true; \n } else if (s1.size() > s2.size()) {\n return false; \n } else {\n return s1 < s2; \n }\n }\n \n vec...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n\n vector<string> res;\n unordered_map<string,unordered_set<int>> sub_map;\n\n for(int i=0;i<arr.size();i++)\n {\n for(int j=0;j<arr[i].size();j++)\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string, int> substrs;\n vector<vector<string>> ith_susbtrs(arr.size(), vector<string>());\n\n int ind = 0;\n for (auto &s : arr) {\n int l = s.length();\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string, int> substrs;\n vector<vector<string>> ith_susbtrs(arr.size(), vector<string>());\n\n int ind = 0;\n for (auto &s : arr) {\n int l = s.length();\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n = arr.size();\n unordered_map<string, int>m;\n vector<unordered_map<string, int>>self(n);\n for(int i=0; i<n;i++){\n unordered_map<string, int>s;\n for(int j=0; ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n = arr.size();\n vector<string> ans;\n unordered_map<string, int> mp;\n for(int i=0; i<n; i++){\n string s = arr[i];\n int m = s.size();\n for(int j=0;...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n vector<multiset<string>> vss(21);\n int n=arr.size();\n vector<vector<string>> mvs(n);\n for(int i=0;i<n;++i)\n {\n int len=arr[i].size();\n vector<string> &vs=...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n \n struct node{\n public:\n vector<node*> child;\n vector<int> subIndex;\n node(){\n child.resize(26, nullptr);\n }\n };\n \n vector<string> shortestSubstrings(vector<string>& arr) {\n node* ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n static bool compareSubstrings(const string& s1, const string& s2) {\n if (s1.length() == s2.length()) {\n return s1 < s2; // Lexicographic comparison if lengths are equal\n }\n return s1.length() < s2.length(); // Compare by length first\n}\n vector<string>...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n unordered_map<string,int>mp;\n \n bool static cmp(string &s ,string &t){\n if(s.size()!=t.size()){\n return s.size()<t.size();\n }\n else{\n return s<t;\n }\n }\n \n vector<vector<string>>helper(vector<string>& arr){\...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class TrieNode{\n public:\n char data;\n bool isTerminal;\n unordered_map<char,TrieNode*> mp;\n vector<int> indexes;\n TrieNode(char x)\n {\n data = x;\n isTerminal = false;\n mp.clear();\n indexes.clear();\n }\n};\nclass Trie{\n public:\n TrieNode*...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n static bool myCmp(pair<string, int>& s1, pair<string, int>& s2)\n{\n if (s1.first.length() != s2.first.length())\n {\n return s1.first.length() < s2.first.length();\n }\n\n return s1.first < s2.first;\n}\n\nvector<string> shortestSubstrings(vector<string>& ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n = arr.size();\n unordered_map<string, unordered_set<int>> exist;\n for (int i = 0; i < n; i++) {\n int sz = arr[i].size();\n\n for (int l = 0; l < sz; l++) {\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n vector<set<string>> subs(arr.size());\n string temp;\n for(int k=0;k<arr.size();k++)\n {\n for(int i=0;i<arr[k].length();i++)\n {\n temp = \"\";\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(string a, string b){\n if(a.size()<b.size())return true;\n if(a.size()==b.size() && a<b) return true;\n return false;\n}\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n=arr.size();\n vector<string> ans(n,\"\");\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n map<string,int> mp;\n vector<string> ans(arr.size(),\"\");\n vector<vector<string>> substrs(arr.size()+1);\n for(int i = 0 ; i<arr.size() ; i++){\n for(int j = 0 ; j<arr[i].size(...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n static bool comp(string a,string b)\n {\n if((a.size()<b.size())||(a.size()==b.size() and a<b))\n {\n return true;\n }\n return false;\n }\n vector<string> shortestSubstrings(vector<string>& arr) {\n int n=arr.size();\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n\n static bool comp(string &a,string &b){\n if(a.size()<b.size())return true;\n else if(a.size()==b.size() && a<b)return true;\n return false;\n }\n vector<string> shortestSubstrings(vector<string>& arr) {\n multiset<string>substrings;\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\n\t// Custom comparision for set contained in subperword\n\tstruct comp {\n\t\tconst bool operator() (const string& x, const string& y) const \n\t\t{\n\t\t\tif (x.size() == y.size())\n\t\t\t\treturn x < y; \n\t\t\treturn x.size() < y.size(); \n\t\t}\n\t};\n\npublic:\n\tvector<string> short...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class trie_node{\npublic:\n trie_node* next[26];\n unordered_set<int> indexs;\n trie_node(){\n for(int i=0; i<26; i++) next[i] = nullptr;\n }\n\n void insert(int index, string& word){\n for(int start=0; start<word.size(); start++){\n trie_node* node = this;\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class trie_node{\npublic:\n trie_node* next[26];\n unordered_set<int> indexs;\n trie_node(){\n for(int i=0; i<26; i++) next[i] = nullptr;\n }\n\n void insert(int index, string& word){\n for(int start=0; start<word.size(); start++){\n trie_node* node = this;\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n static const int N=26;\n \n struct TrieNode {\n TrieNode* childs[N];\n \n TrieNode() {\n for (int i=0; i<N; ++i) {\n childs[i] = nullptr;\n }\n }\n };\n \n class Trie {\n public:\n Tri...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n\tvector<string> shortestSubstrings(vector<string>& arr) \n\t{\n\t\treturn bruteforce(arr); \n\t}\nprivate:\n\tvector<string>bruteforce(vector<string>& arr)\n\t{\n\t\tunordered_map<string, unordered_set<int>>substrings; \n\t\tvector<vector<string>>subperword(arr.size()); \n\n\t\t...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class TrieNode {\n \npublic:\n bool isEndOfWord = false;\n vector<TrieNode*> children;\n TrieNode(): children(26, nullptr) {\n }\n};\n\nclass Trie {\npublic:\n TrieNode* root = new TrieNode();\n\n Trie() {\n \n }\n \n void insert(string word) {\n int i = 0; \n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n\n vector <string> getAllSubstring(string s){\n vector <string> res;\n for(int i=0;i<s.size();i++){\n for(int j=1; j< s.size()- i +1;j++){\n res.push_back(s.substr(i,j));\n\n cout<<s.substr(i,j)<<\" \";\n }\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Node{\n vector<Node *> links;\n unordered_set<int> ids;\n\npublic:\n Node() {\n links.assign(26, NULL);\n }\n\n Node * getKey(char c) {\n return links[c - 'a'];\n }\n\n void createKey(char c) {\n links[c - 'a'] = new Node();\n }\n\n bool hasKey(char c) ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n unordered_map<string, unordered_set<int>> mp;\n vector<vector<string>> temp;\n \n // Generate substrings and track which strings they appear in\n for (int i = 0; i < arr.size(); i++)...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n\nstatic bool comp(const string& a,const string& b)\n{\n if(a.size() == b.size()) return a<b;\n return a.size() < b.size();\n}\n void possibleSubstring(unordered_map<string, int>& mp, vector<string>& res,\n string s, int index) {\n if (in...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> shortestSubstrings(vector<string>& arr) {\n vector<string> ans;\n unordered_map<string,int> mp;\n unordered_map<string,unordered_map<int,int>> mpi;\n for(int ind=0;ind<arr.size();++ind){\n string s = arr[ind];\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n vector<string> generateSubstrings(string str){\n unordered_set<string> st;\n \n for (int i = 0; i < str.length(); i++) {\n string subStr;\n \n for (int j = i; j < str.length(); j++) {\n subStr += str[j];\n ...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\n class Node {\n public:\n Node *next[26];\n int count;\n\n void insert(string &s, int cur)\n {\n Node *node=this;\n for (int i=cur; i<s.size(); i++)\n {\n if (node->next[s[i]-'a']==NULL) node->next[s[i]-'a']...
3,356
<p>You are given an array <code>arr</code> of size <code>n</code> consisting of <strong>non-empty</strong> strings.</p> <p>Find a string array <code>answer</code> of size <code>n</code> such that:</p> <ul> <li><code>answer[i]</code> is the <strong>shortest</strong> <span data-keyword="substring">substring</span> of ...
3
{ "code": "class Solution {\npublic:\n struct Trie {\n Trie* child[26] = {nullptr};\n int cnt{0};\n\n void insert(const string &s, int start) {\n Trie *node = this;\n int sz = s.size();\n for (int i = start; i < sz; i++) {\n int x = s[i] - 'a';\n...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
0
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n long long ans=x;\n for(int i=0;i<n-1;i++){\n ans=(ans+1)|x;\n }\n return ans;\n }\n};", "memory": "8200" }
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
0
{ "code": "class Solution\n{\npublic:\n long long minEnd(int n, int x)\n {\n auto res = 0LL;\n auto b = 0;\n n--;\n\n while (x || n)\n {\n if (x & 1)\n {\n res |= (1LL << b);\n x >>= 1;\n b++;\n }\n ...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
0
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n long long res = x;\n long long N = n - 1;\n long long X = x;\n\n int bit = 0;\n for (int b = 0; b < 62; b++) {\n if ((X >> b) & 1) continue;\n\n res |= (((N >> bit) & 1) * 1LL << b);\n...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
0
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n long long res = 0;\n long long mul = 1; \n n--;\n while(n>0 || x>0) {\n if(x%2) {\n res += mul;\n }\n else {\n res += mul*(n%2);\n n /=...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
1
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n long long ans = x; \n long long newn = n - 1;\n\n int j = 0; \n while (newn != 0) {\n if (((ans >> j) & 1LL) == 0) {\n ans |= ((newn & 1LL) << j); \n newn >>= 1LL; \n ...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
2
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n vector<int>vx(64,0);int i=63,X=x;long long ans=x;\n while(X){\n vx[i]=(X&1);X=X>>1;i--;\n }n--;\n for(int i=63;i>=0&&n;i--){\n if(vx[i]==0){\n vx[i]=(n&1);\n n=n...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
2
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n \n const long long CONST_INT_BIT_LENGTH = 64; \n vector<bool> hasBit (CONST_INT_BIT_LENGTH, false); \n\n // Mark x's bit position \n for (int i=0; i<CONST_INT_BIT_LENGTH; ++i) {\n if (((long long...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
2
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n vector<int> bits_x(64,0);\n vector<int> bits_n(32,0);\n // int top_n = -1;\n for(int i=0;i<=31;i++){\n if((x&(1<<i))!=0){\n bits_x[i] = 1;\n }\n\n if(((n-1)&(1<<i)) ...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
2
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n n--;\n swap(n,x);\n long long nn = n;\n long long xx = x;\n \n vector<int> v,tt;\n while(xx)\n {\n v.push_back(xx&1);\n xx>>=1;\n }\n \n while(nn)\n {\n tt.push...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
2
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n n--;\n swap(n,x);\n long long nn = n;\n long long xx = x;\n \n vector<int> v,tt;\n while(xx)\n {\n v.push_back(xx&1);\n xx>>=1;\n }\n \n while(nn)\n {\n tt.push...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
2
{ "code": "class Solution {\npublic:\n long long minEnd(int n, int x) {\n n--;\n swap(n,x);\n long long nn = n;\n long long xx = x;\n \n vector<int> v,tt;\n while(xx)\n {\n v.push_back(xx&1);\n xx>>=1;\n }\n \n while(nn)\n {\n tt.push...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
3
{ "code": "// // class Solution {\n// // public:\n// // long long minEnd(int n, int x) {\n// // vector<int> xbit(64,0);\n// // vector<int> nbit(64,0);\n\n// // for(int i=0;i<32;i++)\n// // {\n// // xbit[i]=(x>>i)&1;\n// // nbit[i]=(n>>i)&1;\n// // }\...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long minEnd(int n, int x) {\n n--;\n vector<int> xBit(64,0);\n vector<int> nBit(64,0);\n\n for(int i=0; i<32; i++){\n xBit[i] = (x>>i)&1;\n nBit[i] = (n>>i)&1;\n }\n\n int i=0, j=0;\n ...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
3
{ "code": "class Solution {\npublic:\n vector<int> getBin(int x)\n {\n vector<int> ans; \n while(x){\n if(x % 2 == 0){\n ans.push_back(0);\n }\n else{\n ans.push_back(1);\n }\n x >>= 1; \n }\n\n reve...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
3
{ "code": "class Solution {\nprivate:\n //integer to binary starting with MSB (Most Significant Bit)\n string intToBinary(int n) {\n bool foundFirstOne = false;\n string binaryString = \"\";\n int size = sizeof(n) * 8;\n for (int i = size - 1; i >= 0; --i) {\n if ((n & (1 ...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
3
{ "code": "class Solution {\npublic:\n\n int get_bit(int n, int pos)\n {\n return ((1LL<<pos)&n)!=0;\n }\n\n long long minEnd(int n, int x) {\n\n vector<int> free;\n vector<int> p2;\n\n long long res = x;\n\n for(int i=0;i<64;i++)\n {\n if(!get_bit(x,i...
3,394
<p>You are given two integers <code>n</code> and <code>x</code>. You have to construct an array of <strong>positive</strong> integers <code>nums</code> of size <code>n</code> where for every <code>0 &lt;= i &lt; n - 1</code>, <code>nums[i + 1]</code> is <strong>greater than</strong> <code>nums[i]</code>, and the result...
3
{ "code": "class Solution {\npublic:\n\n int get_bit(int n, int pos)\n {\n return ((1LL<<pos)&n)!=0;\n }\n\n long long minEnd(int n, int x) {\n\n vector<int> free;\n vector<int> p2;\n\n long long res = x;\n\n for(int i=0;i<64;i++)\n {\n if(!get_bit(x,i...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "using ll = long long;\nshort M[100010];\nint S = 0;\nclass Solution {\npublic:\n ll counting(int x, vector<int>& nums){\n memset(M, 0, sizeof(M));\n S = 0;\n ll n = nums.size(), i = 0, j = 0, ans = 0;\n while(j < n){\n S += ++M[nums[j++]] == 1;\n while(S...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n const int n = static_cast<int>(nums.size());\n auto subarray = [&](int k) -> long\n {\n long result = 0;\n int count[100'001] = {};\n for (int l = 0, r = 0; r < n; ++r)\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n if(nums.size() == 1) return 1;\n long long n = nums.size() * (nums.size() + 1) / 2;\n unordered_map<int, int> is_visited;\n long long left = 0, right = nums.size() + 1, mid, count, unique, p;\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "static int x = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n array<int,100009> count = {0};\n // Return how many subarrays have fewer than x unique elements\n a...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "// static int x = []() {\n// std::ios::sync_with_stdio(false);\n// std::cin.tie(nullptr);\n// return 0;\n// }();\nclass Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n array<int,100009> count = {0};\n // Return how many subarrays have fewer than x unique elem...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n using ll = long long;\n\n ll SubarraysWithAtmostKDistinctElements(vector<int>& nums, int k) {\n ll totalCount = 0;\n int n = nums.size();\n int Freq[100005] = {};\n int left = 0, right = 0;\n int currCount = 0;\n\n while (right < n) {\n if (++Freq[n...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n\n using ll = long long;\n \n ll SubarraysWithAtmostKDistinctElements(vector<int>& A, int K) {\n ll subarrays = 0 , Freq[100005]{};\n for(int L = 0 , R = 0 ; R < A.size() ; R++){\n K -= Freq[A[R]]++ == 0;\n while(K < 0) K += --Freq[A[L...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n const long long n = nums.size();\n int low = 1;\n int high = n;\n long long median = ((n * (n + 1) / 2) + 1) / 2;\n\n vector<int> freq(1e5 + 10);\n\n while (low < high) {\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "static int x = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n if(nums.size() == 1) return 1;\n long long n = nums.size() * (nums.size() + 1) / 2;\n unordered_m...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n unordered_map<int, int> count;\n\n // Return how many subarrays have fewer than x unique elements\n auto getPos = [&](int x) {\n count.clear();\n auto low = nums.begin();\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n long long check(int a,vector<int>& nums)\n {\n int n=nums.size();\n int l=0;\n int h=0;\n int cnt=0;\n long long ans=0;\n vector<int> freq(1e5+1,0);\n while(h<n)\n {\n if(freq[nums[h]]==0)\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "long long NumArrays(vector<int>& nums, int uniq) {\n if (uniq == 0) return 0;\n int i = 0;\n vector<int> m(1e5+2);\n int d = 0;\n long long ans = 0;\n for (int j = 0; j < nums.size(); ++j) {\n if (m[nums[j]] == 0) {\n ++d;\n }\n ++m[nums[j]];\n while (i < j && d > uniq) {\n --m[...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n int medianOfUniquenessArray(vector<int>& nums) {\n int n=nums.size();\n long long total=(long long) n*(n+1)/2;\n int ans=-1;\n int lo=1, hi=n;\n while (lo<=hi){\n vector<int> count(100005,0);\n int mid=(lo+hi)/2;\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n bool check(int n, vector<int>& nums, int x) {\n long long all = 1LL * n * (n + 1) / 2;\n long long left = 0;\n int uniq = 0;\n vector<int> cnt(100001);\n int j = -1;\n\n for (int i = 0; i < n; i++) {\n while (j < n && uniq ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n long countSubarrayOfMaxLen(vector<int>& nums, int len) {\n long n = nums.size();\n vector<int> cnts;\n int cnt = 0;\n cnts.resize(1e5 + 2);\n\n long count = 0;\n int end = -1;\n for (int i = 0; i < n; i++) {\n int nu...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n\n\nclass Solution {\npublic:\n long long total;\n\n \n bool check(int mid, vector<int>& nums) {\n int n = nums.size();\n int tail = 0;\n int head = -1;\n long long count = 0;\n long long distinctCount = 0;\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\nconst int N = 1e5+1;\nlong long func(int k, vector<int> &nums){\n int n = nums.size();\n long long cnt=0, ct=0;\n int i=0, j=0;\n vector<int> mp(N, 0);\n while(j<n){\n mp[nums[j]]++;\n if(mp[nums[j]]==1) ct++;\n while(i<j && ct>k){\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n\n long long check(vector<int> &nums,int k)\n {\n long long count=0;\n vector<int> freq(100005,0);\n\n for(int l=0,r=0;r<nums.size();r++)\n {\n k=k-(freq[nums[r]]++==0);\n while(k<0)\n k+=--freq[nums[l++]]==0;\n count+=(r-l+1);\n }\n\n ...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n int check(vector<int>&nums, int mid){\n int n = nums.size();\n int head = -1 ;\n int maxi = -1e9 ;\n for(int i =0 ; i<nums.size(); i++){\n maxi = max(maxi,nums[i]);\n }\n int tail =0 ;\n long long totsub = ((n)*(n+1...
3,362
<p>You are given an integer array <code>nums</code>. The <strong>uniqueness array</strong> of <code>nums</code> is the sorted array that contains the number of distinct elements of all the <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code>. In other words, it is a sorted array consisting of <c...
0
{ "code": "class Solution {\npublic:\n\n// #of subarrays where unique elements are atmost mid is <=median\n bool check(int mid,vector<int>& nums){\n int head = -1;\n int tail =0;\n long long n = nums.size();\n long long ans=0;\n int maxi = -1e9;\n for(auto it: nums) maxi = max(max...