id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n static constexpr int NUM_BITS = 10;\r\n using Parities = std::bitset<NUM_BITS>;\r\n\r\n long long wonderfulSubstrings(const string& word) {\r\n auto all_even = Parities{};\r\n std::unordered_map<Parities, int> parity_freqs = {\r\n {Parities{... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int n = word.length();\r\n unordered_map<char, int > hash;\r\n int mask = 1;\r\n for(int i = 0; i<10; i++)\r\n {\r\n hash['a' + i] = mask;;\r\n mask *= 2;\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int n=word.size(),s=(1<<11);\r\n vector<long long int>v(s,0);\r\n v[0]=1;\r\n long long int ans=0;\r\n int temp=0;\r\n for(int i=0;i<n;i++){\r\n temp^=(1<<(word[i]-'a'));... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n vector<long long> arr(2055);\r\n int n=word.size();\r\n vector<int> a(10,0);\r\n long long ans=0;\r\n int x;\r\n arr[0]=1;\r\n int c;\r\n int y;\r\n for(int i=0... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\n public:\r\n long long wonderfulSubstrings(const std::string &word)\r\n {\r\n unordered_map<int, int> prefix_count;\r\n prefix_count[0] = 1; // Start with prefix 0, to handle the case when a substring itself is wonderful.\r\n int prefix = 0;\r\n long... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int mask = 0;\r\n unordered_map<int,int> mp;\r\n int n = word.size();\r\n long long ans = 0;\r\n for(int i = 0;i<n;i++){\r\n int ch = word[i]-'a';\r\n int bit = mask>... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int xor_all = 0;\r\n long long count = 0;\r\n unordered_map<int, int> freq;\r\n freq[0] = 1;\r\n\r\n for(auto c: word){\r\n int index = c - 'a';\r\n xor_all ^= (1<<in... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int xor_all = 0;\r\n long long count = 0;\r\n unordered_map<int, int> freq;\r\n freq[0] = 1;\r\n\r\n for(auto c: word){\r\n int index = c - 'a';\r\n xor_all ^= (1<<in... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "#include <vector>\r\n#include <unordered_map>\r\n#include <string>\r\nusing namespace std;\r\n\r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n long long count = 0;\r\n unordered_map<int, long long> prefixCount;\r\n int currentMask = 0;\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n size_t count = 0;\r\n uint32_t mask = 0;\r\n std::unordered_map<uint32_t, size_t> masks_counts;\r\n for (char ch : word) {\r\n mask ^= (1 << (ch - 'a'));\r\n\r\n count += (m... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n unordered_map<int,int>mp;\r\n mp[0]=1;\r\n int parity=0;\r\n long long ans=0;\r\n for(char ch:word){\r\n parity = parity ^ (1<<(ch-'a'));\r\n ans+=mp[parity];\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n \r\n unordered_map<int, int> mp;\r\n mp[0]=1;\r\n int xxor=0;\r\n\r\n long long ans=0;\r\n\r\n for(int i=0; i<word.size(); i++)\r\n {\r\n int mask = 1;\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n unordered_map<int,int>mp;\r\n mp[0]=1;\r\n int parity=0;\r\n long long ans=0;\r\n for(char ch:word){\r\n parity = parity ^ (1<<(ch-'a'));\r\n ans+=mp[parity];\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "// Sure! Let’s break it down in simpler terms:\r\n\r\n// The goal is to count how many \"wonderful\" substrings exist in a given string. A \"wonderful\" substring is defined as a string where:\r\n\r\n// Either all letters appear an even number of times, OR\r\n// Exactly one letter appears an odd number of ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 1 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n long long cnt=0;\r\n int x=0,n=word.size();\r\n unordered_map<int,int>mp;\r\n mp[0]=1;\r\n for(int i=0;i<n;i++){\r\n int d=1<<(word[i]-'a');\r\n x^=d;\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n using ll=long long;\r\n int n=word.size();\r\n unordered_map<char,int>mask;\r\n mask['a']=1,mask['b']=2,mask['c']=4,mask['d']=8,mask['e']=16,mask['f']=64,mask['g']=128,mask['h']=256,mask['i']=512... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n unordered_map<int, int> count;\r\n int mask = 0;\r\n count[0] = 1;\r\n long long result = 0;\r\n for(char c : word) {\r\n mask ^= 1 << (c - 'a');\r\n result += count[... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution {\r\npublic:\r\n #define ll long long\r\n long long wonderfulSubstrings(string s) {\r\n ll ans =0;\r\n map<int,int>mp;\r\n mp[0] = 1;\r\n int curr = 0,n = s.size();\r\n for(int i=0;i<n;i++){\r\n curr ^=(1<<(s[i]-'a'));\r\n if(mp.... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "#define ll long long\r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n ll ans = 0 ; unordered_map<char,int> mpp ; unordered_map<int,int> last ;\r\n for(int i=0;i<10;i++){\r\n char ch = 'a' + i ;\r\n mpp[ch] = i ;\r\n } \r\n\r\n... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int mask = 0;\r\n map<int,int> mp;\r\n int n = word.size();\r\n set<int> st;\r\n \r\n int m = st.size();\r\n long long ans = 0;\r\n for(int i = 0;i<n;i++){\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "using ll=long long;\r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n ll n=word.size();\r\n\r\n ll parity_mask=0;\r\n unordered_map<ll,ll> prefix_parity;\r\n prefix_parity[0]=1;\r\n\r\n ll count=0;\r\n for(ll i=0; i<n; i++){\r\n... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "using ll=long long;\r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n ll n=word.size();\r\n\r\n ll parity_mask=0;\r\n unordered_map<ll,ll> prefix_parity;\r\n prefix_parity[0]=1;\r\n\r\n ll count=0;\r\n for(ll i=0; i<n; i++){\r\n... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int code=0;\r\n unordered_map<int,long long> mp;\r\n mp[code]=1;\r\n long long res=0;\r\n for(auto c: word){\r\n code^=(1<<(c-'a'));\r\n res+=mp[code];\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution\r\n{\r\npublic:\r\n long long wonderfulSubstrings(string word)\r\n {\r\n int n = word.length();\r\n int mask = 0;\r\n long long ans = 0;\r\n unordered_map<int, long long> M;\r\n M[0]=1;\r\n for (int i = 0; i < n; i++)\r\n {\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 2 | {
"code": "class Solution\r\n{\r\npublic:\r\n long long wonderfulSubstrings(string word)\r\n {\r\n int n = word.length();\r\n int mask = 0;\r\n long long ans = 0;\r\n unordered_map<int, long long> M;\r\n M[0]=1;\r\n for (int i = 0; i < n; i++)\r\n {\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution\r\n{\r\npublic:\r\n long long wonderfulSubstrings(string word)\r\n {\r\n int n = word.length();\r\n int mask = 0;\r\n long long ans = 0;\r\n unordered_map<int, long long> M;\r\n M[0]=1;\r\n for (int i = 0; i < n; i++)\r\n {\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string s) {\r\n ios::sync_with_stdio(0); cin.tie(0);\r\n int n = s.size();\r\n long long res = 0;\r\n bitset<10>val(0);\r\n unordered_map<bitset<10>,long long>mp; mp[val] = 1;\r\n for(int i=0;i<n;i++)... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string s) {\r\n ios::sync_with_stdio(0); cin.tie(0);\r\n int n = s.size();\r\n long long res = 0;\r\n long long val = 0;\r\n unordered_map<long long,long long>mp; mp[0] = 1;\r\n string tmp = \"abcdefg... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string s) {\r\n ios::sync_with_stdio(0); cin.tie(0);\r\n int n = s.size();\r\n long long res = 0;\r\n long long val = 0;\r\n unordered_map<long long,long long>mp; mp[0] = 1;\r\n for(int i=0;i<n;i++){\... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n int n = word.size();\r\n unordered_map<int,int> m;\r\n m[0] = 1;\r\n int mask = 0;\r\n long long ans = 0;\r\n for(int i = 0; i < n; i++) {\r\n int c = (word[i] - 'a');\r\... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "using ll = long long;\r\n\r\nclass Solution {\r\npublic:\r\n ll wonderfulSubstrings(string s) {\r\n int n = s.size();\r\n\r\n auto word = [&](char ch) { return (ch - 'a'); };\r\n\r\n // {mask, ind}\r\n map<int, int> mp;\r\n int currMask = 0;\r\n mp[currMask] = 1... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n long long cnt=0;\r\n int x=0,n=word.size();\r\n map<int,int>mp;\r\n mp[0]=1;\r\n for(int i=0;i<n;i++){\r\n int d=1<<(word[i]-'a');\r\n x^=d;\r\n cnt+=mp[x]... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n map<int,int> freq;\r\n\r\n freq[0]=1;\r\n int mask = 0;\r\n long res = 0 ;\r\n for(int i = 0 ; i<word.size() ; i++)\r\n {\r\n int c = word[i]-'a';\r\n\r\n mask... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\npublic:\n long long wonderfulSubstrings(string s) {\n int bit=0;\n int n=s.size();\n long long cnt=0;\n map<int,long long>mp;\n mp[0]=1;\n long long curr=0;\n for(int i=0;i<n;i++){\n int c=s[i]-'a';\n curr^=(1<<c);\... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n map<int,int> freq;\r\n\r\n freq[0]=1;\r\n int mask = 0;\r\n long res = 0 ;\r\n for(int i = 0 ; i<word.size() ; i++)\r\n {\r\n int c = word[i]-'a';\r\n\r\n mask... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n // vector<int>value{0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};\r\n // unordered_map<int, int>mp;\r\n // mp[0] = 1;\r\n // long long value1 = 0, ans = 0;\r\n // for(int i = 0; i < wo... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "#define ll long long\r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n unordered_map<int,int> mp;\r\n int n = word.size();\r\n ll prefix = 0, ans = 0;\r\n mp[0] = 1;\r\n for(int i=0;i<n;i++)\r\n {\r\n int x = word[i]-... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "#define ll long long \r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n\r\n map<ll,ll>mp;\r\n\r\n ll mask = 0,ans=0;\r\n mp[0] = 1;\r\n for(int i=0;i<word.size();i++)\r\n {\r\n mask = mask ^ (1<<(word[i] - 'a'));\r\n ... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "#define ll long long \r\nclass Solution {\r\npublic:\r\n long long wonderfulSubstrings(string word) {\r\n unordered_map <ll,ll> mp;\r\n ll ans=0,mask=0;\r\n mp[0]=1;\r\n for(int i=0;i<word.size();i++) {\r\n //prefix sum xor\r\n mask=mask ^ (1 << (word[i]... |
2,044 | <p>A <strong>wonderful</strong> string is a string where <strong>at most one</strong> letter appears an <strong>odd</strong> number of times.</p>
<ul>
<li>For example, <code>"ccjjc"</code> and <code>"abab"</code> are wonderful, but <code>"ab"</code> is not.</li>
</ul>
<p>Given a s... | 3 | {
"code": "class Solution {\r\npublic:\r\n long long wonderfulSubstrings(string s) {\r\n unordered_map <long long, long long> d;\r\n long long ans=0, mask=0;\r\n\r\n d[0] = 1;\r\n for(int i=0;i<(int)s.size();i++){\r\n mask = mask ^ (1 << (s[i]-'a'));\r\n ans += d[m... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n for(int i = 0; i < n; i++){\n if(dist[i] % speed[i] == 0) dist[i]--;\n dist[i] /= speed[i];\n }\n speed.assign(n, 0);\n for(int i = ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n for(int i = 0; i < n; i++){\n if(dist[i] % speed[i] == 0) dist[i]--;\n dist[i] /= speed[i];\n }\n speed.assign(n, 0);\n for(int i = ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n for(int i = 0; i < n; i++){\n int rem = dist[i] % speed[i];\n dist[i] = dist[i]/speed[i];\n if(rem)\n dist[i] += 1;\n }\... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n for(int i = 0; i < dist.size(); i++){\n float x = dist[i], z = speed[i];\n dist[i] = ceil(x/z);\n }\n \n sort(dist.begin(), dist.end());\n\n int cnt = 0;\n... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n for(int i = 0; i < n; i++){\n if(dist[i] % speed[i] == 0) dist[i]--;\n dist[i] /= speed[i];\n }\n sort(dist.begin(), dist.end());\n ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n for(int i=0 ; i<dist.size() ; i++){\n if(dist[i]%speed[i]==0){dist[i]/=speed[i];}\n else{\n dist[i]/=speed[i];\n dist[i]++;\n }\n }\n ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n float time[speed.size()];\n\n for(int i=0;i<speed.size();i++)\n {\n time[i]=float(dist[i])/speed[i]-1;\n \n }\n sort(time,time+speed.size());\n int co... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\n public:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n const int n = dist.size();\n vector<int> arrivalTime(n);\n\n for (int i = 0; i < n; ++i)\n arrivalTime[i] = (dist[i] - 1) / speed[i];\n\n ranges::sort(arrivalTime);\n\n for (int i = 0; i < n; +... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\n public:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n const int n = dist.size();\n vector<int> arrivalTime(n);\n\n for (int i = 0; i < n; ++i)\n arrivalTime[i] = (dist[i] - 1) / speed[i];\n\n ranges::sort(arrivalTime);\n\n for (int i = 0; i < n; +... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n vector<int> monsters(n, 0);\n\n for (int i = 0; i < n; i++) {\n int arrival = ceil(static_cast<double>(dist[i]) / speed[i]);\n\n if (arrival < n) ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\n public:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n const int n = dist.size();\n vector<int> arrivalTime(n);\n\n for (int i = 0; i < n; ++i)\n arrivalTime[i] = (dist[i] - 1) / speed[i];\n\n ranges::sort(arrivalTime);\n\n for (int i = 0; i < n; +... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 0 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n vector<int> v(n+1, 0);\n for(int i=0; i<n; i++){\n int t = ceil((float)dist[i] / speed[i]);\n t = min(n, t);\n v[t]++;\n }\n ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n vector<int> overAllDist(n, 0);\n \n for(int i = 0; i < n; i++) {\n overAllDist[i] = ceil((float)dist[i] / (float)speed[i]);\n }\n sort(b... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n=dist.size();\n\n vector<int>time (n);\n for(int i=0;i<n;i++){\n time[i]=ceil((float)dist[i]/speed[i]);\n }\n sort(time.begin(), time.end());\n\n int coun... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\nstatic bool cmp(double a, double b){\n return a < b;\n}\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n vector<double> vect(n,0);\n for(int i=0;i<n;i++){\n vect[i] = (double)((double)dist[i]/(double)sp... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int> &dist, vector<int> &speed) {\n int n = dist.size();\n vector<double> arrival(n);\n for (int i = 0; i < n; i++) {\n arrival[i] = (double) dist[i] / speed[i];\n }\n ranges::sort(arrival);\n fo... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\nSolution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n}\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n=dist.size();\n vector<double> time(n);\n for(int i=0; i<n; i++){\n time[i] = (... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& sp) {\n int n=sp.size();\n vector<double> ti(n);\n for(int i=0;i<n;i++) ti[i]=(double)dist[i]/(double)sp[i];\n sort(ti.begin(),ti.end());\n \n for(int i=0;i<n;i++){\n if(... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n auto remain = vector<double>(n);\n for (int i=0;i<n;++i) remain[i] = (double)dist[i]/speed[i];\n sort(begin(remain), end(remain));\n int cnt = 1;\n ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n\n // Calculate time to reach the city for each monster\n vector<double> timeToReach(n);\n for (int i = 0; i < n; i++) {\n timeToReach[i] = (double)dist[i] / speed[i];\n ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& sp) {\n int n=sp.size();\n vector<double> ti(n);\n for(int i=0;i<n;i++) ti[i]=(double)dist[i]/(double)sp[i];\n sort(ti.begin(),ti.end());\n \n for(int i=0;i<n;i++){\n if(... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<double> time(dist.size());\n \n for (int i = 0; i < dist.size(); ++i) {\n time[i] = static_cast<double>(dist[i]) / speed[i];\n }\n sort(time.begin(), time.end(... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n =dist.size();\n vector<double> time(n);\n for(int i=0;i<n;++i){\n time[i] = (double)dist[i]/speed[i];\n }\n sort(time.begin(),time.end());\n for(auto t:t... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base :: sync_with_stdio(false);\n }\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<int>timeOfArrival;\n int n = dist.size();\n for(int i = 0;i<n;i++){\n int time = ceil(((double)dist[i])/speed[i... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<int>time;\n int i,j,k,c=0;\n\n for(i=0;i<dist.size();i++){\n if(dist[i]%speed[i]==0)\n time.push_back((dist[i]/speed[i]));\n else\n time.pus... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 1 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n \n int n=dist.size();\n\n vector<int>v;\n\n for(int i=0;i<n;i++){\n double x=dist[i]/(speed[i]*1.0);\n v.push_back(ceil(x));\n }\n\n sort(v.begin(),v.... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 2 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int len = dist.size();\n vector<int> remTime;\n for(int i=0; i<len; i++){\n remTime.push_back((dist[i] + speed[i] -1)/speed[i]);\n }\n sort(remTime.begin(), remTime.e... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 2 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n vector<float> v;\n for(int i = 0 ; i < n ; i++){\n v.push_back((float) dist[i] / speed[i]);\n }\n sort(v.begin(), v.end());\n int count ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n=dist.size();\n // vector <pair<int,int>> m;\n vector<float>m;\n\n for(int i=0;i<n;i++){\n // m.push_back({dist[i],speed[i]});\n m.push_back(dist[i]/float(sp... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int n = dist.size();\n // vector <pair<int,int>> m;\n vector<float> m;\n\n for (int i = 0; i < n; i++) {\n // m.push_back({dist[i],speed[i]});\n m.push_back(dist[... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<float> time;\n for(int i = 0; i<dist.size(); i++){\n time.push_back((float)dist[i]/speed[i]);\n }\n sort(time.begin(), time.end());\n for(auto i: time) cout<<i... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n#define pi pair<int,int>\n int eliminateMaximum(vector<int>& arr, vector<int>& brr) {\n int n=arr.size();\n vector<pi>t(n);\n vector<int>time(n);\n\n///time found\nfor(int i=0;i<n;i++){\n\ntime[i]=(arr[i]%brr[i]==0)?arr[i]/brr[i]:(arr[i]/brr[i])+1;\n\n}\n\... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n#define pi pair<int,int>\n int eliminateMaximum(vector<int>& arr, vector<int>& brr) {\n int n=arr.size();\n vector<pi>t(n);\n vector<int>time(n);\n\n///time found\nfor(int i=0;i<n;i++){\n\ntime[i]=(arr[i]%brr[i]==0)?arr[i]/brr[i]:(arr[i]/brr[i])+1;\n\n}\n\... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<int> times;\n for(int i = 0; i < dist.size(); i++){\n int time = ceil(double(dist[i]) / double(speed[i]));\n times.push_back(time);\n }\n\n sort(times.begi... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<int> times;\n for(int i = 0; i < dist.size(); i++){\n int time = ceil(double(dist[i]) / double(speed[i]));\n times.push_back(time);\n }\n\n sort(times.begi... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n\n static bool cmp (pair<int,int> a, pair<int, int> b) {\n return (float) a.first / a.second < (float) b.first / b.second;\n }\n\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<pair<int,int>> dist_speed_pairs;\n for (int i = ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n vector<double>time;\n int n = dist.size();\n\n for(int i = 0; i < n; ++i){\n time.push_back(double(dist[i])/speed[i]);\n }\n\n sort(time.begin(), time.end());\n\n ... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n/*\nPremium qs of lc of goofav on gfg: \nq1. https://www.geeksforgeeks.org/assign-campus-bikes-to-workers/\nmethod1: sort triplets and greedily assign to the workers tc: O(n*m * log(n*m))\nmethod2: bucket sort : vector< vector<triplets> > buckets i.e. for dis =d ,we have vector o... |
2,049 | <p>You are playing a video game where you are defending your city from a group of <code>n</code> monsters. You are given a <strong>0-indexed</strong> integer array <code>dist</code> of size <code>n</code>, where <code>dist[i]</code> is the <strong>initial distance</strong> in kilometers of the <code>i<sup>th</sup></cod... | 3 | {
"code": "class Solution {\npublic:\n int eliminateMaximum(vector<int>& dist, vector<int>& speed) {\n int curr_time=0;\n vector<double>time;\n for(int i=0;i<dist.size();++i)\n {\n double d=dist[i],sp=speed[i];\n time.push_back({d/sp});\n }\n sort(tim... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n sort(nums.begin(), nums.end());\n int n = nums.size();\n int cnt = 1;\n int ans = 0;\n for(int i = 1; i<n; ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(std::vector<int>& nums) \n{\n \n std::sort(nums.begin(), nums.end());\n \n for(auto el : nums)\n {\n std::cout << el << \" \";\n }\n \n std::cout << std::endl;\n \n size_t res = 0;\n... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& a) {\n int i=0,j=0,n=a.size(),ans=0;\n sort(a.begin(),a.end());\n for(i=0;i<n;)\n {\n while(j<n&&a[i]==a[j])\n j++;\n int cnt = j-i;\n if(cnt==1) return -1;\n int... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& tasks) {\n int n = tasks.size();\n sort(tasks.begin(),tasks.end());\n int i = 0; \n\n int cnt = 0;\n \n while( i < n ){\n int j = upper_bound(tasks.begin(),tasks.end(),tasks[i]) - tasks.begin(... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& tasks) { \n sort(tasks.begin(), tasks.end());\n int result = 0, i, j;\n for(i=0; i<tasks.size(); ++i){\n for(j=i+1; j<tasks.size(); ++j)\n if(tasks[i]!=tasks[j]) break;\n \n j ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<int>v;\n int count=1,operation=0;\n\n for(int i=0;i<nums.size();i++){\n if(nums[i]!=-999){\n count=1;\n for(int j=i+1;j<nums.s... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int>mp;\n for(int i=0; i<nums.size(); i++){\n mp[nums[i]]++;\n } \n\n int ans=0;\n\n for(auto it:mp){\n\n int freq=it.second;\n\n if(freq==1){\n ans=-... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int>mp;\n int n=nums.size();\n int count=0;\n for(int i=0;i<n;i++)\n {\n mp[nums[i]]++;\n }\n for(auto it:mp)\n {\n if(it.second==1)\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n int n=nums.size();\n\n sort(nums.begin(),nums.end());\n\n unordered_map<int,int>mp;\n\n for(int i=0;i<n;i++){\n\n mp[nums[i]]++;\n\n }\n\n int cnt=0;\n\n for(auto it:mp){\n\n int... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n int n=nums.size();\n\n sort(nums.begin(),nums.end());\n\n unordered_map<int,int>mp;\n\n for(int i=0;i<n;i++){\n\n mp[nums[i]]++;\n\n }\n\n int cnt=0;\n\n for(auto it:mp){\n\n int... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 0 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int> a;\n for(int i:nums)\n a[i]++;\n int counter=0;\n for(auto& [v,f] :a)\n {\n if(f == 1)\n return -1;\n if(f % 3 == 0)\n {\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 1 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int> a;\n for(int i:nums)\n a[i]++;\n int counter=0;\n for(auto& [v,f] :a)\n {\n if(f == 1)\n return -1;\n if(f % 3 == 0)\n {\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(auto x:nums)\n mp[x]++;\n int ans=0;\n for(auto x:mp){\n if(x.second==1) return -1;\n if(x.second%3==0){\n ans+=x.second/3;\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 2 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int> counts;\n int ans = 0;\n\n for (int num: nums) {\n counts[num]++;\n }\n\n for (pair<int,int> it: counts) {\n if (it.second == 1) {\n return ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& v) {\n map<int, int> m;\n for (int i : v)\n m[i]++;\n \n int ans = 0;\n for (auto [i, j] : m) {\n if (j % 3 == 0)\n ans += j / 3;\n else if (j % 3 == 2)\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int> counts;\n int ans = 0;\n\n for (int num: nums) {\n counts[num]++;\n }\n\n for (pair<int,int> it: counts) {\n if (it.second == 1) {\n return ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n\n map<int,int>mp;\n for(auto it:nums)\n {\n mp[it]++;\n }\n\n int count=0;\n for(auto it:mp)\n {\n int val=it.second;\n if(it.second<2)return -1;\n\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n map<int, int> mp;\n sort(nums.begin(), nums.end()); // 222233344\n for (int i : nums)\n mp[i]++; // 4 3 2\n int count = 0;\n for (auto i = mp.begin(); i != mp.end(); i++)\n {\n int occurrences = i->sec... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i:nums)\n {\n mp[i]++;\n }\n vector<int> new_arr;\n for(auto it:mp)\n {\n new_arr.push_back(it.second);\n }\n int... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n\n int n = nums.size();\n unordered_map<int, int> freq;\n for (auto& i : nums) {\n freq[i] += 1;\n }\n vector<int> f;\n for (auto& i : freq) {\n f.push_back(i.second);\n ... |
3,094 | <p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>
<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>
<ul>
<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete... | 3 | {
"code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n std::unordered_map<int, size_t> counts;\n\n for(auto el : nums)\n {\n if(counts.end() == counts.find(el))\n {\n counts[el] = 1;\n }\n else\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.