id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "bool sortCondition(pair<int,int> &pq1,pair<int,int> &pq2)\n{\n return pq1.second>pq2.second;\n}\nclass Solution {\npublic:\n int minimumPushes(string &word) {\n int ans=0;\n vector<pair<int,int>> pq;\n for(int i=0;i<26;i++)\n {\n pq.push_back({i,0});\n }\...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "bool sortCondition(pair<int,int> &pq1,pair<int,int> &pq2)\n{\n return pq1.second>pq2.second;\n}\nclass Solution {\npublic:\n int minimumPushes(string &word) {\n int ans=0;\n vector<pair<int,int>> pq;\n for(int i=0;i<26;i++)\n {\n pq.push_back({i,0});\n }\...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(const std::string& word) {\n std::unordered_map<char, int> freqMap;\n\n // Count frequencies of each character\n for (const char& ch : word) {\n freqMap[ch]++;\n }\n\n // Create a vector to store frequencies\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n // count the frequencies\n vector<unsigned> count(26, 0);\n for (const char c : word) {\n ++count.at(c - 'a');\n // ++count[c - 'a'];\n }\n \n // create a maxHeap out of the fre...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string& word) {\n vector<int> mapping(26, 0);\n const int SZ { int(word.size()) };\n for (int i = 0; i < SZ; i++)\n mapping[word[i] - 'a']++;\n multiset<int, std::greater<int>> remapping;\n for (char i = 0; i < 2...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n// naive solution\n// idea - the most frequent letters should cost less pushes\n// \n// count frequencies of each letter in word\n// sort letters by their frequencies in descending order\n// 'place' the most frequent letters as close to the beginnning in button as possible\n\n// ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(const string &word) {\n\n unordered_map<char, int> counter;\n for (char ch : word)\n counter[ch]++;\n\n vector<pair<char, int>> VecCounter(counter.begin(), counter.end());\n // Use a lambda function for sorting\n sort(VecCounter.begin(), Ve...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(std::string_view word) {\n std::unordered_map<char, int> counts;\n for(char c : word)\n counts[c]++;\n \n std::priority_queue<int> pq;\n for(auto& p : counts)\n pq.push(p.second);\n int pressCou...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string& word) {\n array<int, 26> cnt{};\n for (char c : word) ++cnt[c - 'a'];\n sort(cnt.rbegin(), cnt.rend());\n int res = 0, i = 0;\n for (int n : cnt) res += n * ((i++ >> 3) + 1);\n return res;\n }\n};", "mem...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int minimumPushes(string& word) {\n array<int, 26> cnt{};\n for (char c : word) ++cnt[c - 'a'];\n sort(cnt.rbegin(), ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int minimumPushes(string& word) {\n array<int, 26> cnt{};\n for (char c : word) ++cnt[c - 'a'];\n sort(cnt.rbegin(), ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "#include <unordered_map>\n#include <vector>\n#include <algorithm>\n#include <string>\n\nclass Solution {\npublic:\n static bool cmp(const std::pair<char, int>& a, const std::pair<char, int>& b) {\n return a.second > b.second;\n }\n\n int minimumPushes(const std::string& word) {\n std...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(const std::string& word) {\n // Count frequency of each character\n std::unordered_map<char, int> freq;\n for (char c : word) {\n freq[c]++;\n }\n\n // Sort characters by frequency in descending order\n st...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(const string& word) {\n vector<int> frequency(26, 0);\n for (char c : word) {\n frequency[c - 'a']++;\n }\n \n vector<int> freqs;\n for (int freq : frequency) {\n if (freq > 0) {\n freqs.push_back(freq);\n }\...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(const std::string& word) {\n std::vector<int> freq(26, 0);\n\n // Count the frequency of each letter\n for (char c : word) {\n freq[c - 'a']++;\n }\n\n // Sort frequencies in descending order\n std::sort(f...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string& word) {\n vector<int> ans(26,0);\n for(int i = 0;i<word.size();i++){\n ans[word[i] - 'a']++;\n }\n sort(ans.rbegin(), ans.rend());\n int res = 0;\n int next = 0;\n for(int i = 0; i<26 && ans...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution\n{\npublic:\n int minimumPushes(string& word)\n {\n vector<int> freq(26);\n\n for (char c : word)\n {\n freq[c - 'a']++;\n }\n \n sort(freq.rbegin(), freq.rend());\n int result = 0;\n for (int i = 0; i < freq.size(); i+...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n static int minimumPushes(string& word) {\n vector<int>mp(26,0);\n for(char &ch: word){\n mp[ch-'a']++;\n }\n sort(mp.rbegin(),mp.rend());//decending order\n int result=0;\n\n for(int i=0;i<26;i++){\n int freq=mp[...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "#include <unordered_map>\n#include <string>\n\nclass Solution {\npublic:\n int minimumPushes(const std::string& word) {\n int result = 0;\n vector<int> vec(26,0);\n\n for(auto it:word){\n vec[it-'a']++;\n }\n\n sort(vec.rbegin(), vec.rend());\n for(in...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> cnt(26);\n for(auto &i : word) {\n ++cnt[i - 'a'];\n }\n sort(cnt.begin(), cnt.end(), greater<int>());\n int ans = 0;\n for(int i = 0; i < 26; ++i) {\n if (cnt[i] == 0)\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "using namespace std;\n\nclass Solution {\nprivate:\n int solve(const vector<pair<char, int>>& temp) {\n int ans = 0;\n int cnt = 1;\n int size = temp.size();\n int eight=8;\n for (int i = 0; i < size; i++) {\n if (eight==0)\n {\n ei...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> f(26);\n for(auto x:word){\n f[x-'a']++;\n }\n sort(f.begin(),f.end());\n reverse(f.begin(),f.end());\n int ans = 0;\n int ii = 0;\n for(int i=0;i<26;i++){\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> cnt(26, 0);\n for (auto& ch : word)\n cnt[ch - 'a']++;\n \n int res = 0;\n sort(cnt.begin(), cnt.end(), greater<int>());\n for (int i = 0; i < 26; i++) {\n res += (i...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int>v(26,0);\n for(int i=0;i<word.size();i++)\n {\n v[word[i]-'a']++;\n }\n sort(v.begin(),v.end(),greater<int>());\n \n int ans=0;\n int temp=0;\n for(auto i=0...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) \n {\n vector<int> mp(26,0);\n for(char &ch:word)\n {\n mp[ch-'a']++;\n }\n sort(begin(mp),end(mp), greater<int>());\n\n int result = 0;\n for(int i=0;i<26;i++)\n {\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> f(26,0);\n for(int i=0;i<word.length();i++)\n f[word[i]-'a']++;\n int ans=0;\n sort(f.begin(),f.end(),greater<int>());\n for(int i=0;i<26;i++){\n if(i<8)\n ans+=f[i]...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int>mp(26,0);\n for(char &ch:word){\n mp[ch-'a']++;\n }\n sort(begin(mp),end(mp),greater<int>());//sorting in decending order\n int res=0;\n for(int i=0;i<26;i++){\n int ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
0
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int ans=0;\n vector<int> freq(26,0);\n for(auto it: word){\n freq[it-'a']++;\n }\n sort(freq.begin(),freq.end(),greater<int>());\n for(int i=0;i<26;i++){\n if(i<8){\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\n public:\n int minimumPushes(string word) {\n int ans = 0;\n vector<int> count(26);\n\n for (const char c : word)\n ++count[c - 'a'];\n\n ranges::sort(count, greater<>());\n\n for (int i = 0; i < 26; ++i)\n ans += count[i] * (i / 8 + 1);\n\n return ans;\n }\n...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "#include<bits/stdc++.h>\n\nclass Solution {\npublic:\n\n\n int minimumPushes(string word) {\n \n vector<int> freq(26, 0);\n for( auto x: word ) \n freq[x-'a']++;\n \n sort( freq.begin(), freq.end(), greater<int>());\n\n int n=0, ans=0, seg=1;\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "#include<bits/stdc++.h>\n\nclass Solution {\npublic:\n\n\n int minimumPushes(string word) {\n \n vector<int> freq(26, 0);\n for( auto x: word ) \n freq[x-'a']++;\n \n sort( freq.begin(), freq.end(), greater<int>());\n\n int n=0, ans=0, seg=1;\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n\n int arr[27] = {0};\n //count the occurence, put to array\n for (int i=0;i<word.length();i++) {\n arr[word[i]-'a']++;\n }\n \n //iterate the array, put to vector\n vector<int> v;\n...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> freq(26);\n for(char s:word)\n {\n freq[s-'a']++;\n }\n vector<int> p;\n for(int i=0;i<26;i++)\n {\n if(freq[i])\n p.push_back(freq[i]);\n }...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n const int available_keys = 8;\n\n vector<int> alpha(26, 0);\n for (char ch : word)\n alpha[ch - 'a']++;\n\n vector<int> f;\n for (int i=0; i<26; i++)\n {\n if (alpha[i])\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "constexpr size_t SIZE = 'z' + 1;\nconst size_t CLICKABLE_BUTTONS = 8;\nconst size_t MAX_LETTERS_IN_BUTTON = 4;\nclass Solution {\npublic:\n int minimumPushes(string word) {\n array<int, SIZE> arr{};\n for(const char& c : word){\n ++arr[c];\n }\n\n sort(arr.begin() ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int n = word.size();\n vector<int>freq(26,0), typeCount(26,0);\n vector<pair<int,int>>freqLetter(26);\n\n int uniqueLetterCount = 0, totalPushNeeded = 0;\n \n for(auto ch : word) {\n freq[...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string str) {\n vector<int> word(26, 0);\n vector<pair<int, int> > sorted_word;\n for(auto ch: str){\n word[ch - 'a']++;\n }\n for(int i = 0; i < 26; i++){\n if(word[i] > 0) {\n sorted_w...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) { \n\n int arr[26];\n int n = word.size();\n for(int i=0;i<n;i++) {\n arr[word[i]-'a']++;\n }\n \n priority_queue<int>pq;\n for(int i=0;i<26;i++) {\n if(arr[i]!=0) {\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> cntChar;\n priority_queue<pair<int,int>> pq;\n int total = 0,\n type = 1,\n cnt = 1;\n \n cntChar.resize(26,0);\n for(char w: word) cntChar[w-'a']++;\n for(in...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "#include <unordered_map>\nclass Solution {\npublic:\n int minimumPushes(string word) {\n std::unordered_map<char, int> myMap;\n int lastIndex = word.length()-1;\n std::string myWord;\n int wordIndex = 0;\n //Store each character in word and its frequency in a hashmap\n...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "#include <unordered_map>\nclass Solution {\npublic:\n int minimumPushes(string word) {\n std::unordered_map<char, int> myMap;\n int lastIndex = word.length()-1;\n std::string myWord;\n int wordIndex = 0;\n int index=0;\n //Store each character in word and its fr...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "#include <unordered_map>\n#include<iostream>\nclass Solution {\npublic:\n int minimumPushes(string word) {\n std::unordered_map<char, int> myMap;\n int lastIndex = word.length()-1;\n std::string myWord;\n int wordIndex = 0;\n //Store each character of word in a hashmap...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "#include <unordered_map>\n#include<iostream>\nclass Solution {\npublic:\n int minimumPushes(string word) {\n std::unordered_map<char, int> myMap;\n int lastIndex = word.length()-1;\n std::string myWord;\n int wordIndex = 0;\n //Store each character in word and its freq...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\n\npublic:\n\n int minimumPushes(string word) {\n\n // Frequency map to store count of each letter\n\n unordered_map<char, int> frequencyMap;\n\n // Count occurrences of each letter\n\n for (char& c : word) {\n\n ++frequencyMap[c];\n\n }\n\n...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n unordered_map<char, int> freq;\n for (char &c : word) {\n ++freq[c];\n }\n priority_queue<int> pq;\n for (auto &elem : freq) {\n pq.push(elem.second);\n }\n\n int res = 0...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
1
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n unordered_map<char, int>mapping;\n for(auto ch:word){\n mapping[ch]++;\n }\n\n vector<int> v;\n for(auto p:mapping){\n v.push_back(p.second);\n cout<<p.second<<endl;\n }\n\n sort(v.begi...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n \n unordered_map<char,int>mpp;\n for(char ch: word){\n mpp[ch]++;\n }\n priority_queue<pair<int, char>>pq;\n\n for(auto it:mpp){\n pq.push({it.second,it.first});\n }\n \n int cn...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n int n = word.length();\n int len = 1;\n int ans = 0;\n\n unordered_map<char,int>mp;\n for(auto &it:word){\n mp[it]++;\n }\n\n vector<pair<int,char>>arr;\n for(auto &it:mp){\n...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n // Frequency vector to store count of each letter\n vector<int> frequency(26, 0);\n\n // Count occurrences of each letter\n for (char& c : word) {\n ++frequency[c - 'a'];\n }\n\n // Sort f...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
2
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int>freq(26,0);\n for(auto i:word)freq[i-'a']++;\n\n sort(freq.rbegin(),freq.rend());\n\n int ans=0;\n int d=1;\n for(auto i:freq){\n if(d<=8)ans+=i;\n else if(d<=16)ans+=...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n vector<int> frequencies(26, 0);\n\n for (auto letter : word)\n {\n frequencies[letter - 'a']++;\n }\n\n sort(frequencies.rbegin(), frequencies.rend());\n\n int totalPushes = 0;\n\n ...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
3
{ "code": "#include <bits/stdc++.h> \nusing namespace std; \nbool cmp(pair<char,int>&a, pair<char,int>&b)\n{\n return a.second>b.second;\n}\n\n int solve(map<char, int>&m)\n {\n vector<pair<char,int>>v;\n for(auto &u:m)\n v.push_back(u);\n sort(v.begin(), v.end(),cmp);\n\n int cnt=1, sum=0;\n\n f...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n map<int,int> mp;\n int total=0;\n int num=0;\n\n for(int i=0; i<word.size(); i++){\n mp[word[i]]++;\n }\n\n vector<pair<int, int>> vec(mp.begin(), mp.end());\n\n auto cmp = [](const...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
3
{ "code": " bool comp(pair<char,int> a,pair<char,int> b){\n return b.second<a.second;\n\n }\nclass Solution {\npublic:\n \n int minimumPushes(string word) {\n map<char,int> map;\n for(int i=0;i<word.size();i++){\n map[word[i]]++;\n }\n int ans=0;\n int coun...
3,276
<p>You are given a string <code>word</code> containing lowercase English letters.</p> <p>Telephone keypads have keys mapped with <strong>distinct</strong> collections of lowercase English letters, which can be used to form words by pushing them. For example, the key <code>2</code> is mapped with <code>[&quot;a&quot;,&...
3
{ "code": "class Solution {\npublic:\n int minimumPushes(string word) {\n map<char,int> mp;\n for(int i=0;i<word.size();i++){\n mp[word[i]]++;\n }\n priority_queue<pair<int,char>> pq;\n for(const auto & it :mp){\n pq.push({it.second,it.first});\n }\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "int sumDigits(int num) {\n int sum = 0;\n while (num) {\n sum += num % 10;\n num /= 10;\n }\n return sum;\n}\n\nint init=[] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n int k;\n for (std::string s; getline(cin, s);) {\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string& s, int k) {\n int num=0;\n for(char x : s) {\n int c = x-'a'+1;\n auto[q, r]=div(c,10);\n num+=q+r;\n }\n if (k==1) return num;\n k--;\n for(int c=num; c>=10 && k>0; k--){\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string& s, int k) {\n int num=0;\n\n for (char c: s){\n int x=c-'a'+1;\n auto [q, r]=div(x, 10);\n num+=q+r;\n }\n\n if (k==1) return num;\n k--;\n for(int x=num; x>=10 && k>0; k--){\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int total = accumulate(cbegin(s), cend(s), 0,\n [](const auto& total, const auto& x) {\n const auto num = x - 'a' + 1;\n return total + n...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n //transform letters, 1st transform\n int sum =0;\n for(char cv:s){\n int d = ( cv - 'a' + 1);\n while(d){\n sum += (d % 10);\n d /= 10;\n }\n }\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int transform(int num) {\n int ans = 0;\n while (num) {\n ans += num%10;\n num /= 10;\n }\n return ans;\n }\n int getLucky(string s, int k) {\n int num = 0;\n k--;\n for (auto &c : s) {\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string& s, int k) {\n int num=0;\n // convert letters to digits\n for (char c: s){\n int x=c-'a'+1;\n auto [q, r]=div(x, 10);// x may has 1~2 digits\n num+=q+r;\n }\n // cout<<num<<endl;\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n long long int currNum = 0;\n for (auto ch : s) {\n auto num = ch - 'a' + 1;\n while (num) {\n currNum += num % 10;\n num = num / 10;\n }\n }\n\n long l...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int sum = 0;\n for (char c : s) {\n int num = c - 'a' + 1;\n while (num > 0) {\n sum =sum+ num % 10; \n num =num/ 10; \n }\n }\n while (--k > 0) {\n int newSum = 0;\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int sum = 0;\n\n for (char ch : s) {\n int val = (int)ch - 'a' + 1;\n while (val > 0) {\n sum += val % 10; \n val /= 10;\n }\n }\n\n for (int i = 1; i ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
0
{ "code": "class Solution {\npublic:\n int getSum(int n)\n {\n int sum =0;\n while(n > 0)\n {\n sum += n%10;\n n /= 10;\n }\n return sum;\n }\n int getLucky(string s, int k) {\n int num =0;\n for(auto c: s)\n {\n int ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n vector<int> positions{};\n int answer{};\n\n for(size_t i{}; i < s.size(); i++)\n {\n char c = s.at(i);\n positions.push_back(c - 'a' + 1);\n }\n\n while(k)\n {\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int brokenSum(int a) {\n int ans = 0;\n while (a != 0) {\n int r = a % 10;\n ans += r;\n a /= 10;\n }\n return ans;\n }\n\n int getLucky(string s, int k) {\n vector<int> ans;\n int i = 0;\n\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n vector<int> arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8};\n\n int sum = 0;\n for(int i=0; i<s.length(); i++)\n {\n int index = s[i] - 'a';\n sum += arr...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n vector<int> nums;\n for(int i=0;i<s.length();i++){\n nums.push_back(s[i]-'a'+1);\n } \n long long int num=0;\n for(int i=0;i<nums.size();i++){\n while(nums[i]>0){\n num+=nums[i]%10;\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n vector<int> arr(s.size());\n\n // for(int i=0;i<s.size();i++) {\n // arr[i] = s[i]-'a'+1;\n // // cout<< arr[i] << endl;\n // }\n\n int sum = 0;\n\n for(int j=0;j<s.size();j++) {\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n\n long long transform2Sum(long long num){\n string trans1_string = std::to_string(num);\n long long start = pow(10,trans1_string.length()-1);\n long long trans2_int = 0;\n for(int i = 0; i < trans1_string.length()-1; i++){\n if(i < trans...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n vector<int>v;\n int val=0;\n for(int i=1;i<27;i++)\n {\n v.push_back(i);\n }\n string s1=\"\";\n for(int i=0;i<s.length();i++)\n {\n if(v[s[i]-'a']>9)\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int sum = 0;\n string curr = s, new_curr;\n for(char c : curr) {\n int n = c - 'a' + 1;\n if(n / 10)\n new_curr += '0' + n / 10;\n new_curr += '0' + n % 10;\n }\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n stringstream ss_digits;\n for (const auto &c: s) ss_digits << c - 'a' + 1;\n \n string digits = ss_digits.str();\n int sum = 0;\n do {\n sum = 0;\n for (const auto &c: digits) su...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n #include <unordered_map>\n\nunordered_map<char, int> m{\n {'a', 1}, {'b', 2}, {'c', 3}, {'d', 4}, {'e', 5}, {'f', 6}, {'g', 7}, {'h', 8}, {'i', 9},\n {'j', 1}, {'k', 2}, {'l', 3}, {'m', 4}, {'n', 5}, {'o', 6}, {'p', 7}, {'q', 8}, {'r...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n string alphabet = \"abcdefghijklmnopqrstuvwxyz\";\n unordered_map<char,int>umap;\n for(int i=0;i<alphabet.length();i++)\n {\n umap[alphabet[i]]=i+1;\n }\n \n int sum=0;\n for(...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n string intToString(int num) {\n string result = \"\";\n if (num == 0) {\n return \"0\";\n }\n while (num > 0) {\n int digit = num % 10; \n result = char(digit + '0') + result; \n num /= 10; \n }\...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int n=s.length();\n int sum=0;\n string t=to_string(s[0]-96);\n for(int i=1;i<n;i++){\n t.append(to_string(s[i]-96));\n }\n cout<<t<<endl;\n for(int i=0;i<t.length();i++){\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n\n int transform(int number){\n int sum=0;\n while(number>0){\n int digit= number%10;\n sum+= digit;\n number=number/10;\n }\n\n return sum;\n }\n int getLucky(string s, int k) {\n string str;\n f...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n string ans = \"\";\n int ret;\n for(auto c: s){\n ans += to_string(c-'a'+1);\n }\n \n for(int i = 1; i <= k; i++){\n ret = 0;\n for(auto c: ans){\n ret ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n\n\n\n string str;\n\n for(char c : s) {\n if(isalpha(c)) { \n \n int val = c - 'a' + 1;\n str += to_string(val); \n }\n }\n int ans = 0;\n while (k-...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int n=s.size();\n string arr;\n for(int i=0;i<n;i++){\n int num=s[i]-'a'+1;\n arr+=to_string(num);\n }\n while(k--){\n long long sum=0;\n for(int i=0;i<arr.size();...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getCharVal(char s)\n {\n return s-'a'+1;\n }\n string transform(string &s)\n {\n string ts= \"\";\n for(int i=0;i<s.size();i++)\n {\n ts+=to_string(getCharVal(s[i]));\n }\n return ts;\n } \n int addAll...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k)\n {\n std::string number; \n for(char c: s)\n {\n int n = c -'a' + 1;\n number.append(std::to_string(n));\n }\n std::cout<<number<<std::endl;\n\n while (--k >= 0)\n {\n ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int len = s.length();\n string str;\n\n for(auto ch: s) {\n str += to_string(int(ch) - 96);\n }\n\n while(k--) {\n int sum = 0;\n for(auto ch: str)\n sum += in...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
1
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n string st;\n\n for(int i=0; i<s.size(); i++){\n int num = s[i] - 'a' + 1;\n st.insert(st.size(), to_string(num));\n }\n\n for(int i=0; i<k; i++){\n int sum = 0;\n for(int...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
2
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n // Convert each character in the string to its corresponding numeric value\n string number = \"\";\n for (char x : s) {\n number += to_string(x - 'a' + 1);\n \n }\n \n // Perform ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
2
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n string number=\"\";\n for(char c:s){\n number+=to_string(1+c-'a');\n }\n while(k>0){\n int temp=0;\n for(char c:number){\n temp+=c-'0';\n }\n nu...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int calculate(string s)\n {\n int sum=0;\n\n for(int i=0;i<s.length();i++)\n {\n sum+=(int)s[i]-48;\n }\n return sum;\n }\n int getLucky(string s, int k) {\n int n=s.length();\n string sum=\"\";\n int...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n\n long long string2Sum(string s){\n long long sum = 0;\n for(int i = 0; i < s.length(); i++){\n sum += s[i] - '0';\n }\n return sum;\n }\n\n int getLucky(string s, int k) {\n string transString = \"\";\n for(int i = 0...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n \n string num = \"\";\n int sum = 0; \n\n for(auto i:s){\n int pos = i - 'a' + 1;\n num += to_st...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n string converted = \"\";\n int value = 0;\n\n if (!isdigit(s[0]))\n for (auto& chr : s)\n converted+= to_string(chr-96);\n else\n converted = s;\n \n\n for (auto& ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int ans = 0;\n vector<pair<char, int>> alphabetPairs = {\n {'a', 1}, {'b', 2}, {'c', 3}, {'d', 4}, {'e', 5}, \n {'f', 6}, {'g', 7}, {'h', 8}, {'i', 9}, {'j', 10}, \n {'k', 11}, {'l', 12}, {'m', 1...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n int stringSize = s.size();\n int result = 0;\n //created a hashmap of char and its respective count;\n unordered_map<char, int> hashmap;\n\n for (char ch = 'a'; ch <= 'z'; ++ch) {\n hashmap[ch] = ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n unordered_map<char, int> alphabet = {\n {'a', 1}, {'b', 2}, {'c', 3}, {'d', 4}, {'e', 5}, {'f', 6},\n {'g', 7}, {'h', 8}, {'i', 9}, {'j', 10}, {'k', 11}, {'l', 12},\n {'m', 13}, {'n', 14}, {'o',...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int processNum(string s, int k) {\n if (k == 0) {\n return stoi(s);\n }\n\n int num = 0;\n for (int i = 0; i < s.size(); i++) {\n num += s[i] - '0';\n }\n\n if (k > 0) {\n return processNum(to_string(n...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\nint getLucky(string s, int k) {\n string convert = \"\";\n int result = 0;\n for(int i = 0; i < s.size(); i++) {\n convert += to_string(stoi(to_string(s.at(i))) - 97 + 1);\n }\n int j = 0;\n while(j < k) {\n result = 0;\n for(int L = 0; L < ...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int getLucky(string s, int k) {\n long long int num=0;\n string str=\"\";\n for(auto it: s)\n {\n str= str+ to_string(it-'a'+1);\n }\n cout<<str<<endl;\n \n while(k--)\n {\n int s=0;\n for(auto i...
2,076
<p>You are given a string <code>s</code> consisting of lowercase English letters, and an integer <code>k</code>.</p> <p>First, <strong>convert</strong> <code>s</code> into an integer by replacing each letter with its position in the alphabet (i.e., replace <code>&#39;a&#39;</code> with <code>1</code>, <code>&#39;b&#39...
3
{ "code": "class Solution {\npublic:\n int processNum(string s, int k) {\n if (k == 0) {\n return stoi(s);\n }\n\n int num = 0;\n for (int i = 0; i < s.size(); i++) {\n num += s[i] - '0';\n }\n\n if (k > 0) {\n return processNum(to_string(n...