id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 1 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long count = 0;\n unordered_set<string> sett(ideas.begin(),ideas.end());\n vector<vector<int>> vec(26,vector<int>(26,0));\n for(int i=0;i<ideas.size();i++){\n string word=ideas[i];\... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 1 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> mp;\n long long dp[26][26]={0};\n long long res=0;\n for(auto& el: ideas)\n {\n mp.insert(el);\n }\n\n for(int i=0; i<ideas.size(); i++)\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 1 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> st(ideas.begin(),ideas.end());\n int n=ideas.size();\n vector<vector<ll>> hash(26,vector<ll>(26,0));\n for(auto &it:ideas){\n char f=it[0];\n... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& a) {\n unordered_set<string>s;\n for(auto it : a) s.insert(it);\n\n vector<vector<long long>>v(26,vector<long long>(26,0));\n for(auto it : a){\n char tmp=it[0];\n for(char c='a';c<='z';... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n vector<set<string>> hash(26);\n for(auto it:ideas) {\n hash[it[0]-'a'].insert(it.substr(1, it.size()-1));\n }\n long long ans = 0;\n for(int i=0;i<26;i++) {\n for(int j... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas){\n vector<set<string>>um(26);\n for(auto word:ideas)um[word[0]-'a'].insert(word);\n long long ans=0LL;\n for(int i=0;i<25;i++){\n for(int j=i+1;j<26;j++){\n long long intersec... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n set<string> vec[26];\n long long ans = 0;\n\n for(auto j:ideas){\n vec[j[0]-'a'].insert(j.substr(1,j.size()-1));\n }\n\n // for(auto j:vec[2])cout<<j<<\"\\n\";\n for(int i=... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<char,set<string>> mp; //creating a unordered_map w[0] as key and w[1 to n] as value stored in a set.\n for(int i=0;i<ideas.size();i++){\n mp[ideas[i][0]].insert(ideas[i].substr(1));\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution\n{\npublic:\n long long distinctNames(vector<string> &ideas)\n {\n unordered_map<char, set<string>> um;\n set<char> starts;\n for (string idea : ideas)\n {\n um[idea[0]].insert(idea.substr(1));\n starts.insert(idea[0]);\n }\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n map<char,set<string>> m;\n int n=ideas.size();\n for(int i=0;i<n;i++){\n m[ideas[i][0]].insert(ideas[i].substr(1,ideas[i].size()-1));\n }\n long long ans=0;\n for(auto i=m.... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n int n=ideas.size();\n map<char,set<string>> m;\n for(int i=0;i<n;i++){\n m[ideas[i][0]].insert(ideas[i].substr(1));\n }\n long long res=0;\n for(int i=0;i<... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ans = 0;\n vector<vector<long long>>cnt(26,vector<long long>(26,0));\n set<string>st(ideas.begin(),ideas.end());\n for(auto it:ideas){\n int i = it[0]-'a';\n for(int... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\n unordered_map<string, bitset<26>> umsv;\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n umsv.reserve(10000);\n\n }\n\nlong long distinctNames(const vector<string> &ideas) {\n unordered_map<string, bi... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n int n = ideas.size();\n map<string,int> mp;\n for(auto it:ideas){\n mp[it]++;\n }\n vector<vector<int>> dp(26,vector<int>(26,0));\n\n for(int i=0; i<n; i++){\n string ut = idea... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n int n = ideas.size();\n map<string,int> mp;\n for(auto it:ideas){\n mp[it]++;\n }\n vector<vector<int>> dp(26,vector<int>(26,0));\n\n for(int i=0; i<n; i++){\n string ut = idea... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> ump(ideas.begin(), ideas.end());\n vector<vector<int>> cur(128, vector<int>(128,0));\n \n long long ans = 0;\n for (string& s : ideas) {\n for (char c='a'; c... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> ump(ideas.begin(), ideas.end());\n vector<vector<int>> cur(128, vector<int>(128,0));\n \n long long ans = 0;\n for (string& s : ideas) {\n for (char c='a'; c... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n // ios_base::sync_with_stdio(false);\n // cin.tie(NULL);\n\n // unordered_map<char, vector<string>> map;\n vector<unordered_map<string, bool>> map;\n for(int i=0; i<26; i++){ \n m... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<string, bool> mp;\n vector<bool> store(26, 0);\n\n for(auto s : ideas){\n mp[s] = true;\n store[s[0] - 'a'] = 1;\n }\n\n vector<vector<int>> DP(26, vector... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n vector<unordered_map<string, bool>> map;\n for(int i=0; i<26; i++){ \n map.push_back(unordered_map<string, bool>());\n m... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<string, bool> mp;\n vector<bool> store(26, 0);\n\n for(auto s : ideas){\n mp[s] = true;\n store[s[0] - 'a'] = 1;\n }\n\n vector<vector<int>> DP(26, vector... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& s) {\n int n = s.size();\n unordered_map<string,bool> mp;\n for(auto x:s)\n {\n mp[x]=true;\n }\n vector<vector<long long >> dict(26,vector<long long> (26,0));\n for(int i=0;i<... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string>ump(ideas.begin(),ideas.end());\n vector<vector<long long>>cur(128,vector<long long>(128,0));\n long long ans=0;\n for(string &s:ideas){\n for(char j='a';j<='z';j++)... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ans = 0;\n map<char, long long> map1;\n map<string, vector<char>> map2;\n for(int i=0;i<ideas.size();i++){\n map1[ideas[i][0]]++;\n map2[ideas[i].substr(1)].push_bac... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ans = 0;\n map<char, long long> map1;\n map<string, vector<char>> map2;\n for(int i=0;i<ideas.size();i++){\n map1[ideas[i][0]]++;\n map2[ideas[i].substr(1)].push_bac... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 2 | {
"code": "class Solution {\npublic:\n\nlong long distinctNames(vector<string>& ideas) {\n map<int ,unordered_set<string> > mp;\n long long ans =0;\n for(auto it: ideas){\n mp[it[0]-'a'].insert(it.substr(1));\n }\n//******************************************\n\nfor(auto it: mp){\n auto it1=mp.find(it.first);\... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> ideaSet(ideas.begin(), ideas.end());\n vector<unordered_set<string>> suffixes(26);\n for (const string& idea : ideas) {\n suffixes[idea[0] - 'a'].insert(idea.substr(1));\n... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& arr){\n map<char, set<string>> mp;\n for(auto i : arr){\n mp[i[0]].insert(i.substr(1));\n }\n vector<string> res(1e4);\n long long cnt = 0;\n for(char c='a' ; c<='z' ; c++){\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n vector<set<string>> vis(26);\n map<pair<int,string>, int> mp;\n for(auto v: ideas){\n char c=v[0];\n string s=v.substr(1,v.length()-1);\n vis[c-'a'].insert(s);\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<string,int> m1;\n for(string s:ideas)\n m1[s]++;\n vector<unordered_map<string,int>> strs(26);\n for(auto x:m1){\n strs[x.first[0]-'a'][x.first.substr(1)]=1;\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n \n int n = ideas.size();\n map<char, unordered_set<string>> mp;\n\n for(int i = 0; i < n; i++) {\n mp[ideas[i][0]].insert(ideas[i].substr(1));\n }\n long long ans = 0;\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ret=0;\n unordered_map<string,unordered_set<char>> last;\n for(auto &s:ideas){\n char tmp=s[0];\n s[0]='_';\n last[s].insert(tmp);\n s[0]=tmp;\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "using namespace std;\n\nclass Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n // Step 1: Group ideas by their first letter\n unordered_map<char, unordered_set<string>> groups;\n for (const auto& idea : ideas) {\n groups[idea[0]].insert(idea.substr... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<string,int> m1,m2;\n for(string s:ideas){\n m1[s]++;\n m2[s]=1;\n }\n vector<unordered_map<string,int>> strs(26);\n for(auto x:m1){\n strs[x.fi... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<string, unordered_set<char>> suffixGroups;\n vector<unordered_set<string>> prefixGroups(26);\n\n for (auto& idea : ideas) {\n string suffix = idea.substr(1);\n char pre... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ret = 0;\n\n array<vector<string>, 26> has;\n for (auto const& s: ideas)\n {\n has[s[0] - 'a'].push_back(s.substr(1));\n }\n\n for (int i = 0; i < 26; i++)\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_set<string> filterSet(ideas.begin(),ideas.end());\n vector<string> filter(filterSet.begin(),filterSet.end());\n long long ret=0;\n unordered_map<string,unordered_set<char>> last;\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // umsv.reserve(10000);\n\n }\n int numCommonEle(vector<string>& v1,vector<string>& v2){\n unordered_set<string> st;\n for(auto x:v1)st.insert... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // umsv.reserve(10000);\n\n }\n int numCommonEle(vector<string>& v1,vector<string>& v2){\n unordered_set<string> st;\n for(auto x:v1)st.insert... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n int numCommonEle(vector<string>& v1,vector<string>& v2){\n unordered_set<string> st;\n for(auto x:v1)st.insert(x);\n int ans=0;\n for(auto x:v2){\n if(st.count(x))ans++;\n }\n return ans;\n }\n long long getCombo(int ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n // umsv.reserve(10000);\n\n }\n int numCommonEle(vector<string>& v1,vector<string>& v2){\n unordered_set<string> st;\n for(auto x:v1)st.insert... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<char, unordered_set<string>> wordMap;\n long long count = 0;\n\n for (string idea : ideas) {\n wordMap[idea[0]].insert(idea.substr(1));\n }\n\n for (auto curr = word... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n map<char, vector<string>> m;\n \n\n for (int i = 0; i < ideas.size(); i++) {\n char firstChar = ideas[i][0];\n string suffix = ideas[i].substr(1, ideas[i].size() - 1);\n m... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<char, unordered_set<string>> m;\n for (int i = 0; i < ideas.size(); i++) {\n m[ideas[i][0]].insert(ideas[i]);\n }\n ll cnt =0;\n for (auto it =... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n int common_ele(unordered_set<string> s1, unordered_set<string> s2){\n int count = 0; \n for(auto str : s1){\n if (s2.find(str)!=s2.end()){\n count++;\n }\n }\n return count;\n }\n long long distinctNames(v... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas)\n {\n unordered_map<int, unordered_set<string>> first_letter_to_substrings;\n\n for (string idea : ideas)\n {\n int first_letter = idea[0] - 'a';\n\n string substring = idea.substr(1)... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<int, unordered_set<string>>mpp;\n long long res = 0;\n\n\n for(auto &it : ideas) mpp[it[0]].insert(it.substr(1,it.size()-1)); \n\n \n for(int i = 0; i < 26; i++)\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<int,unordered_set<string>> st;\n\n for(string idea: ideas){\n int firstletter = idea[0]-'a';\n string sub = idea.substr(1);\n st[firstletter].insert(sub);\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n\n long long distinctNames(vector<string>& ideas){\n\n \n unordered_map<int, unordered_set<string>>mpp;\n long long res = 0;\n\n\n for(auto &it : ideas) mpp[it[0]].insert(it.substr(1,it.size()-1)); \n\n \n for(int i = 0; i < 26; i... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n map<char, unordered_set<string>> m;\n \n for(int i = 0; i < ideas.size(); i++){\n m[ideas[i][0]].insert(ideas[i].substr(1, ideas[i].size() - 1));\n }\n long long ans = 0;\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "typedef long long ll;\nclass Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n \n\n int n=ideas.size();\n ll ans=0;\n unordered_map<char,unordered_set<string>> mp;\n\n for(auto s:ideas){\n mp[s[0]].insert(s.substr(1,s.size()-1));\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ans = 0;\n unordered_map<char, unordered_set<string>> mp;\n for(string idea : ideas){\n mp[idea[0]].insert(idea.substr(1));\n }\n for(auto p1 : mp){\n for(aut... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long ans = 0;\n map<char, unordered_set<string>> mp;\n for(string idea : ideas){\n mp[idea[0]].insert(idea.substr(1));\n }\n for(auto p1 : mp){\n for(auto p2 : mp)... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long count=0;\n vector<unordered_set<string>>arr(26);\n for(string i:ideas)\n arr[i[0]-'a'].insert(i.substr(1));\n for(int i=0; i<25;i++){\n for(int j=i+1;j<26;j++){\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n long long disName = 0;\n vector<unordered_set<string>> arr(26);\n for (string s : ideas) \n arr[s[0] - 'a'].insert(s.substr(1));\n \n for (int i = 0; i < 25; i++) {\n ... |
2,390 | <p>You are given an array of strings <code>ideas</code> that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:</p>
<ol>
<li>Choose 2 <strong>distinct</strong> names from <code>ideas</code>, call them <code>idea<sub>A</sub></code> and <code>idea<su... | 3 | {
"code": "class Solution {\npublic:\n long long distinctNames(vector<string>& ideas) {\n unordered_map<int, set<string>> appears;\n\n for (auto &idea: ideas) {\n int front = idea[0] - 'a';\n string back = idea.substr(1, idea.size() - 1);\n appears[front].insert(back)... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 0 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int count=0;\n int n=tickets.size();\n while(true){\n if(tickets[k]==0) \n break;\n for(int i=0;i<n;i++){\n if(tickets[k]==0)\n break;... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 0 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int ans = 0;\n\n for (int i = 0; i < tickets.size(); ++i)\n if (i <= k)\n ans += min(tickets[i], tickets[k]);\n else\n ans += min(tickets[i], tickets[k] - 1);\n\n return ans;\n }\n};",
... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 0 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int counter = 0, target = tickets[k];\n for(int i = 0; i < tickets.size(); i++){\n if(i > k && tickets[i] >= target){\n counter --;\n }\n counter += min(ticket... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 0 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int time = 0;\n int i = 0;\n while(tickets[k] != 0){\n if(tickets[i] != 0){\n time++;\n tickets[i]--;\n }\n i++;\n i = i % tic... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 0 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int c=0;\n while(true){\n if(tickets[k]==0)\n break;\n for(int i=0;i<tickets.size();i++){\n if(tickets[k]==0)\n break;\n ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 0 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int c=0,i=0;\n while(tickets[k]!=0){\n if(tickets[i]>0){\n c++;\n tickets[i]--;\n i=(i+1)%tickets.size();\n }\n else if(tickets[i... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int result =0 ;\n for(int i =0;i<=k;i++){\n tickets[i]--;\n result++;\n }\n int val = tickets[k];\n for(int i =0;i<tickets.size();i++){\n result += min(t... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class person {\n public:\n person* next;\n int index;\n int tickets; \n person(int position, int num): next{nullptr}, index{position}, tickets{num}{}\n};\n\nclass Queue{\n public:\n person* front;\n person* back;\n int size;\n Queue(){\n front = nullptr;\n back =... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n vector<int> others(tickets[k] + 1);\n for (int i = 0; i < tickets.size(); ++i) {\n int num = min(tickets[k], tickets[i]); \n if (i > k) {\n num = min(tickets[k] - 1, num)... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int n=tickets.size();\n int time=0;\n queue<int>q;\n for(int i=0;i<n;i++){\n q.push(i);\n }\n while(tickets[k]!=0){\n tickets[q.front()]--;\n ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int>q;\n int t =0;\n for(int i=0;i<tickets.size();i++){\n q.push(i);\n } \n while(tickets[k]!=0){\n tickets[q.front()]--;\n if(tickets[q.front()... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& arr, int k) {\n int n=arr.size();\n int count=0;\n queue<int>q;\n for(int i=0;i<n;i++){\n if(i==k)q.push(-arr[i]);\n else q.push(arr[i]);\n }\n while(q.size()>0){\n i... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int>q;\n\n for( int i=0;i<tickets.size();i++){\n q.push(i);\n }\n\n int time =0;\n while(!q.empty()){\n time++;\n int index =q.front();\n ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 2 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int>q;\n int time=0;\n for(int i=0;i<tickets.size();i++){\n q.push(i);\n }\n\n while(tickets[k]!=0){\n tickets[q.front()]--;\n if(tickets[q.front()... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int>q;\n int n=tickets.size();\n int time=0;\n for(int i=0;i<n;i++)\n {\n q.push(i);\n }\n while(tickets[k]!=0)\n {\n tickets[q.front()]-... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int>q;\n int n=tickets.size();\n for(int i=0;i<n;i++){\n q.push(i);\n }\n int time=0;\n while(tickets[k]!=0){\n tickets[q.front()]--;\n if(t... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int>q;\n int n=tickets.size();\n \n for(int i=0;i<n;i++)\n q.push(i);\n int time=0;\n while(tickets[k]!=0){\n tickets[q.front()]--;\n ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n return simul(tickets, k);\n }\n int simul(vector<int>& tickets, int k) {\n std::queue<int> line;\n \n for (int i : tickets) line.push(i);\n \n int counter = 0;\n int ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int res = 0;\n queue<int> list;\n for (int i = 0; i < tickets.size(); i++) {\n --tickets[i];\n res++;\n list.push(tickets[i]);\n if (k == i && tickets[i] ==... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n int res = 0;\n queue<int> list;\n for (int i = 0; i < tickets.size(); i++) {\n --tickets[i];\n res++;\n list.push(tickets[i]);\n if (k == i && tickets[i] ==... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> q;\n\n for (int i = 0; i < tickets.size(); i++) {\n q.push(tickets[i]);\n }\n\n int index = k, ans = 1;\n while (!(index == 0 && q.front() == 1)) {\n if ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> q;\n\n for (int i = 0; i < tickets.size(); i++) {\n q.push(tickets[i]);\n }\n\n int index = k, ans = 1;\n while (!(index == 0 && q.front() == 1)) {\n if ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> q;\n\n for (int i = 0; i < tickets.size(); i++) {\n q.push(tickets[i]);\n }\n\n int index = k, ans = 1;\n while (!(index == 0 && q.front() == 1)) {\n if ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> q;\n\n for (int i = 0; i < tickets.size(); i++) {\n q.push(tickets[i]);\n }\n\n int index = k, ans = 1;\n while (!(index == 0 && q.front() == 1)) {\n if ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> q;\n\n for (int i = 0; i < tickets.size(); i++) {\n q.push(tickets[i]);\n }\n\n int index = k, ans = 1;\n while (!(index == 0 && q.front() == 1)) {\n if ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n vector<int> temp(tickets.size(), 0);\n unordered_map<int, int> time;\n int sum = 0;\n int answer = 0;\n while (tickets != temp) {\n\n for (int i = 0; i < tickets.size(); i++) ... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> q;\n int n = tickets.size();\n int time = 0;\n for(int i = 0; i < n; i++) {\n q.push(tickets[i]);\n }\n int count = 0;\n while(true) {\n \n... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> qt;\n int time = 0;\n\n int i = 0;\n\n for (int i =0 ; i< tickets.size(); i++) {\n qt.push(tickets[i]);\n }\n while (tickets[k] != 0) {\n if (qt.f... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<int> qt;\n int time = 0;\n\n int i = 0;\n\n for (int i =0 ; i< tickets.size(); i++) {\n qt.push(tickets[i]);\n }\n while (tickets[k] != 0) {\n if (qt.f... |
2,195 | <p>There are <code>n</code> people in a line queuing to buy tickets, where the <code>0<sup>th</sup></code> person is at the <strong>front</strong> of the line and the <code>(n - 1)<sup>th</sup></code> person is at the <strong>back</strong> of the line.</p>
<p>You are given a <strong>0-indexed</strong> integer array <c... | 3 | {
"code": "class Solution {\npublic:\n int timeRequiredToBuy(vector<int>& tickets, int k) {\n queue<pair<int,int>> Q;\n for(int i = 0 ;i<tickets.size();i++)\n {\n Q.push({tickets[i],i});\n }\n int Second = 0;\n while(!Q.empty())\n {\n auto Fron... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int maxi1=INT_MIN;\n int maxi2=INT_MIN;\n int prod=1;\n for(int i=0;i<nums.size();i++){\n prod=prod*nums[i];\n maxi1=max(prod,maxi1);\n if(prod==0){\n prod=1;\n ... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n\n int n = nums.size();\n\n int m1 = INT_MIN;\n int m2 = INT_MIN;\n \n int prefix = 1;\n int suffix = 1;\n\n int j = n-1;\n\n for(int i = 0; i < n; i ++)\n {\n prefix *= nums[i];\n ... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int n=nums.size();\n if(n==0){return 0;}\n if(n==1){return nums[0];}\n int ans=INT_MIN;\n for(int i=0;i<n;i++)\n {\n int prod=nums[i];\n for(int j=i+1;j<n;j++)\n {... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int maxProduct = nums[0];\n int minProduct = nums[0];\n int result = nums[0];\n for(int i=1; i<nums.size(); i++){\n if(nums[i] < 0){\n swap(maxProduct, minProduct);\n }\n ... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int pre = 1, suff=1;\n int ans = INT_MIN;\n int n = nums.size();\n for(int i = 0;i<n;i++)\n {\n if(pre==0) pre = 1;\n if(suff==0) suff = 1;\n\n pre = pre * nums[i];\n ... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n // Intuitive Approah\n int n = nums.size();\n int prefix = nums[0];\n int prod = nums[0];\n for (int i = 1; i < n; i++) {\n if (prod == 0)\n prod = 1;\n prod *= nums[... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int result = nums[0];\n int currmax = nums[0], currmin = nums[0];\n\n for (int i = 1; i < nums.size(); i++) {\n int tempmax = currmax;\n currmax = max(nums[i], max(currmax * nums[i], currmin * nu... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 0 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int n=nums.size();\n int maxi=INT_MIN;\n int pre=1;\n int suff=1;\n for(int i=0;i<n;i++){\n if(pre==0){\n pre=1;\n }\n if(suff==0){\n suff=1... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 2 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n int ans=INT_MIN;\n for(int i=0;i<nums.size();i++){\n int p=nums[i];\n for(int j=i+1;j<nums.size();j++){\n ans=max(ans,p);\n p*=nums[j];\n }\n ans=max(... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 2 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) \n {\n int n=nums.size();\n int pro1=1,pro2=1,ans1=-1e9,ans2=-1e9;\n for(int i=0;i<n;i++)\n {\n pro1=pro1*nums[i];\n ans1=max(ans1,pro1);\n if(pro1==0){\n pro1=1;\... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 3 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int> A) {\n int n = A.size(), res = A[0], l = 0, r = 0;\n for (int i = 0; i < n; i++) {\n l = (l ? l : 1) * A[i];\n r = (r ? r : 1) * A[n - 1 - i];\n res = max(res, max(l, r));\n }\n return r... |
152 | <p>Given an integer array <code>nums</code>, find a <span data-keyword="subarray-nonempty">subarray</span> that has the largest product, and return <em>the product</em>.</p>
<p>The test cases are generated so that the answer will fit in a <strong>32-bit</strong> integer.</p>
<p> </p>
<p><strong class="example">E... | 3 | {
"code": "class Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);\n int prefix=1,suffix=1,n=nums.size();\n int ans=INT_MIN;\n for(int i=0;i<n;i++){\n if(prefix==0) prefix=1;\n if(suffix==0) suffix=1;\n ... |
153 | <p>Suppose an array of length <code>n</code> sorted in ascending order is <strong>rotated</strong> between <code>1</code> and <code>n</code> times. For example, the array <code>nums = [0,1,2,4,5,6,7]</code> might become:</p>
<ul>
<li><code>[4,5,6,7,0,1,2]</code> if it was rotated <code>4</code> times.</li>
<li><code... | 1 | {
"code": "class Solution {\npublic:\n int findMin(vector<int>& nums) {\n int low = 0, high = nums.size() - 1, middle;\n if (nums[high] >= nums[low])\n return nums[low];\n if (nums.empty()) return -1;\n\n while (low <= high) {\n middle = low + (high - low) / 2;\n ... |
153 | <p>Suppose an array of length <code>n</code> sorted in ascending order is <strong>rotated</strong> between <code>1</code> and <code>n</code> times. For example, the array <code>nums = [0,1,2,4,5,6,7]</code> might become:</p>
<ul>
<li><code>[4,5,6,7,0,1,2]</code> if it was rotated <code>4</code> times.</li>
<li><code... | 1 | {
"code": "class Solution {\npublic:\n int findMin(vector<int>& nums) {\n int l = 0;\n int h = nums.size()-1;\n int res = INT_MAX;\n\n while(l<=h){\n if(nums[l]<nums[h]){\n return min(res, nums[l]);\n }\n\n int m = (l+h)/2;\n re... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.