id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n bool valid(int ci, int cj, int r, int c, vector<vector<int>>& grid)\n {\n if(ci < 0 || ci >= r || cj < 0 || cj >= c || grid[ci][cj] == 1)\n {\n return false;\n }\n return true;\n }\n \n void dfs(int si,int sj, int r, int c, v...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution \n{\npublic:\n int closedIsland(vector<vector<int>>& grid) \n {\n int m = grid.size(), n = grid[0].size(), i, j, cnt = 0;\n vector<vector<bool>> vis(m, vector<bool>(n, false));\n\n for(i = 0; i < m; i++)\n {\n for(j = 0; j < n; j++)\n {...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution \n{\npublic:\n int closedIsland(vector<vector<int>>& grid) \n {\n int m = grid.size(), n = grid[0].size(), i, j, cnt = 0;\n vector<vector<bool>> vis(m, vector<bool>(n, false));\n\n for(i = 0; i < m; i++)\n {\n for(j = 0; j < n; j++)\n {...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "struct pair_hash {\n std::size_t operator()(const std::pair<int, int>& p) const {\n // Combine the hashes of the two integers\n std::size_t h1 = std::hash<int>{}(p.first);\n std::size_t h2 = std::hash<int>{}(p.second);\n return h1 ^ (h2 << 1); // Combine hashes using XOR and ...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\nprivate:\n int n,m;\n bool border(int x,int y){\n if(x==0 || y==0 || x==n-1 || y==m-1){\n return true;\n }\n return false;\n }\n bool check(int x,int y){\n if(x>=0 && y>=0 && x<=n-1 && y<=m-1){\n return true;\n }\n ...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n bool checkBoundaryCell(int x, int y, int m, int n) {\n return (x == 0 || x == m - 1 || y == 0 || y == n - 1);\n }\n int closedIsland(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n int cnt = 0;\n vector<...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n int closedIsland(vector<vector<int>>& grid) {\n int rows = grid.size(), cols = grid[0].size();\n vector<vector<bool>> visited(rows, vector<bool>(cols, false));\n vector<vector<int>> directions({{1,0}, {0,1}, {-1,0}, {0,-1}});\n int ans = 0;\n\n ...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n bool dfs(vector<vector<int>>& grid, int row, int col){\n //grid[row][col] = 2;\n int n = grid.size(), m = grid[0].size();\n if(row == n - 1 || col == m - 1 || row == 0 || col == 0){\n grid[row][col] = -1;\n return false;\n }\n...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n vector<pair<int, int>> GetNeighbors(vector<vector<int>> &grid, int sr, int sc) {\n vector<pair<int, int>> neighbors;\n int delta[] = {-1, 0, 1, 0, -1};\n\n for (int i = 0; i < 4; i++) {\n int nr = sr + delta[i];\n int nc = sc + delta...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n int vis[305][305]={false}; \n int bfs(vector<vector<int>>& grid, int i,int j){\n queue <int>q1;\n queue <int>q2;\n q1.push(i);\n q2.push(j);\n vis[i][j]=1;\n int isOK=1;\n while(!q1.empty()){\n int a=q1.front();q...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n vector<pair<int, int>> GetNeighbors(vector<vector<int>> &grid, int sr, int sc) {\n vector<pair<int, int>> neighbors;\n int delta[] = {-1, 0, 1, 0, -1};\n\n for (int i = 0; i < 4; i++) {\n int nr = sr + delta[i];\n int nc = sc + delta...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n int m, n;\n vector<vector<int>>directions{{-1,0},{1,0},{0,1},{0,-1}};\n bool bfs(vector<vector<int>> &grid, int r, int c) {\n queue<pair<int, int>> q;\n q.push({r, c});\n bool isClosed = true;\n \n while (!q.empty()) {\n aut...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "#include <vector>\n#include <queue>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int m, n;\n vector<vector<int>>directions{{-1,0},{1,0},{0,1},{0,-1}};\n bool bfs(vector<vector<int>> &grid, int r, int c) {\n queue<pair<int, int>> q;\n q.push({r, c});\n bool isClosed =...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n int numIslands = 0; \n int closedIsland(vector<vector<int>>& grid) {\n //create a duplicate of grid where we mark all the visited nodes via a bool, while loop to iterate through everything \n //while everything isn't visited run dfs\n //if we haven't v...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n \n vector<vector<int>> dir{{1,0}, {0,1}, {-1,0}, {0,-1}};\n void bfs(vector<vector<int>>& grid, vector<vector<bool>>& vis, int i, int j){\n \n int m=grid.size();\n int n=grid[0].size();\n queue<pair<int,int>> q;\n q.push({i, j});\n ...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n bool bfs(int i , int j , vector<vector<int>>&grid){\n int n = grid.size();\n int m = grid[0].size();\n queue<pair<int , int>>q;\n q.push({i , j});\n bool ans = true;\n vector<vector<int>>dir = {{0 , 1},{0 , -1},{1 , 0},{-1 , 0}};\n ...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": " /*\n Input: grid = \n [\n [0,0,1,1,0,1,0,0,1,0],\n [1,1,0,1,1,0,1,1,1,0],\n [1,0,1,1,1,0,0,1,1,0],\n [0,1,1,0,0,0,0,1,0,1],\n [0,0,0,0,0,0,1,1,1,0],\n [0,1,0,1,0,1,0,1,1,1],\n [1,0,1,0,1,1,0,0,0,1],\n [1,1,1,1,1,1,0,0,0,0],\n [1,1,1,0...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n int closedIsland(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n vector<vector<int>>visited(n,vector<int>(m,0));\n int ans = 0;\n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++){\n ...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\n vector<vector<int>> dir={{1,0},{0,1},{-1,0},{0,-1}};\n void bfs(vector<vector<int>>& a, int i, int j){\n auto m = a.size(), n=a[0].size();\n queue<vector<int>> q;\n q.push({i,j});\n a[i][j]=1;\n while(!q.empty()){\n auto e = q.front();\...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\n// private:\n// void dfs(vector<vector<int>>& grid, int r, int c) {\n// if (r < 0 || r >= grid.size() || c < 0 || c >= grid[0].size() || grid[r][c] != 0) {\n// return;\n// }\n// grid[r][c] = 2;\n// dfs(grid, r + 1, c);\n// dfs(grid, r - 1, c);\n//...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n \n int closedIsland(vector<vector<int>>& grid) {\n vector<vector<bool>>vis(grid.size() , vector<bool>(grid[0].size()));\n int n = grid.size();\n int m =grid[0].size();\n int count=0;\n for(int i=0;i<n;i++)\n {\n for(int j...
1,380
<p>Given a 2D&nbsp;<code>grid</code> consists of <code>0s</code> (land)&nbsp;and <code>1s</code> (water).&nbsp; An <em>island</em> is a maximal 4-directionally connected group of <code><font face="monospace">0</font>s</code> and a <em>closed island</em>&nbsp;is an island <strong>totally</strong>&nbsp;(all left, top, ri...
3
{ "code": "class Solution {\npublic:\n\nvoid bfs0(vector<vector<int>>& grid, vector<vector<bool>>& v, int x, int y)\n{\n\n queue<pair<int,int>> q;\n q.push({x,y});\n v[x][y]=true;\n\n int m=grid.size();\n int n=grid[0].size();\n\n vector<vector<int>> d = {{1,0}, {-1,0}, {0,1}, {0,-1}};\n\n while(...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
0
{ "code": " class Solution {\npublic:\n int a[26], b[26], ans = 0;\n void solve(int idx, vector<string>& words, vector<int>& score) {\n if (idx == words.size()) {\n int sc = 0;\n for (int i = 0; i < 26; i++) {\n if (b[i] > a[i])return;\n sc += score[i] ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
0
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int cnt[26]{};\n for (char& c : letters) {\n cnt[c - 'a']++;\n }\n int n = words.size();\n int ans = 0;\n for (int i = 0; i < 1 << ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\nprivate:\n struct LetterCount {\n int Count[26] = { 0 };\n\n void Insert(char Letter) {\n ++Count[Letter - 'a'];\n }\n\n void Insert(string& Str) {\n for (int i = 0; i < Str.size(); ++i) Insert(Str[i]);\n }\n\n bool Consum...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\npublic:\n\n int solve(int n,int m,int x,map<char,int>&mp,int ind,vector<string>&v,vector<int>&sc){\n\n if(ind==n){\n return 0;\n }\n\n int pick=0,f=0,score=0;\n for(int i=0;i<v[ind].length();i++){\n char ch=v[ind][i];\n if(mp...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n vector<int> cnt(26, 0);\n int ans = 0;\n for(char& letter:letters)\n cnt[letter - 'a']++;\n solve(words, score, cnt, 0, 0, ans);\n return ans;...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\n vector<string> words;\n vector<int> score;\n array<int, 26> left;\n vector<bool> mark;\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n this->words = vector<string>(words.begin(), words.end());\n this->score =...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n vector<int> cnt(26, 0);\n for (char letter : letters)\n cnt[letter - 'a']++;\n\n map<vector<int>, int> d;\n d[cnt] = 0;\n int res = 0;\n\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n vector<int> cnt(26, 0);\n for (char letter : letters)\n cnt[letter - 'a']++;\n\n map<vector<int>, int> d;\n d[cnt] = 0;\n int res = 0;\n\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\npublic:\n int m;\n int maxscore=INT_MIN;\n void solve(int index,int currentscore,vector<string>& words\n ,vector<int> &freq,vector<int>& score)\n {\n maxscore=max(maxscore,currentscore);\n if(index>=m)\n {\n return;\n }\n vector...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
1
{ "code": "class Solution {\npublic:\n vector<int> freq;\n int maxSum = 0;\n void helper(vector<string>& words, vector<int>& score, int i, int sum){\n if(i == words.size()){\n maxSum = max(maxSum, sum);\n return;\n }\n int scr = 0;\n bool flag = true;\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "class Solution {\npublic:\n int maxScoreWords(std::vector<std::string>& words,\n std::vector<char>& letters,\n std::vector<int>& score)\n {\n int max_score = 0;\n\n std::vector<int> letter_count(26, 0);\n for (const char& chr : letters)\n...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "class Solution {\npublic:\n\n bool check(string s, vector<int>& freq){\n vector<int>currFreq(26,0);\n for(int i = 0 ; i<s.length() ; i++){\n char c = s[i];\n currFreq[c-'a']++;\n if(freq[c-'a'] < currFreq[c-'a']) return false;\n }\n return tru...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "class Solution {\npublic:\n void dfs(vector<string>& words, int index,\n unordered_map<char, int>& char_freq, vector<int>& score,\n int cur_score, int& max_score) {\n if (index == words.size()) {\n max_score = max(max_score, cur_score);\n return;\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "class Solution {\npublic:\n int maxi;\n int n;\n \n void solve(int i , vector<int> &score , vector<string> &words, int curr , vector<int> freq){\n \n maxi = max(maxi,curr);\n \n if(i >= n){\n return;\n }\n // can we take the current word\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "class Solution {\npublic:\n int Max = 0;\n int getscore(string word, unordered_map<char, int>& letter,\n vector<int>& score) {\n int scor = 0;\n for (char a : word) {\n\n if (letter.count(a)) {\n if (letter[a] > 0) {\n\n scor ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "class Solution {\npublic:\n int Max = 0;\n int getscore(string word, unordered_map<char, int>& letter,\n vector<int>& score) {\n int scor = 0;\n for (char a : word) {\n\n if (letter.count(a)) {\n if (letter[a] > 0) {\n\n scor ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "/*\n\nhttps://leetcode.com/problems/maximum-score-words-formed-by-letters/discuss/425129/java-backtrack-similar-to-78.-Subsets-1ms-beats-100\n\nhttps://leetcode.com/problems/maximum-score-words-formed-by-letters/discuss/426045/C++-DFS-(optional-memo)\n\n*/\n\nclass Solution {\npublic:\n int maxScoreWord...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
2
{ "code": "/*\n\nhttps://leetcode.com/problems/maximum-score-words-formed-by-letters/discuss/425129/java-backtrack-similar-to-78.-Subsets-1ms-beats-100\n\nhttps://leetcode.com/problems/maximum-score-words-formed-by-letters/discuss/426045/C++-DFS-(optional-memo)\n\n*/\n\nclass Solution {\npublic:\n int maxScoreWord...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(vector<string>& words,unordered_map<char,int>& mp,int i,vector<int>& score,unordered_map<string,int>& dp)\n {\n if(i>=words.size())\n {\n return 0;\n }\n string key=to_string(i)+'#';\n for(auto &it:mp)\n {\n key...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\nint f(int i,int mask,vector<int>&v,map<char,int>&m,vector<string>& w){\n if(i==w.size())return 0;\n\n int ans=0;\n \n int take=0;\n int not_take=f(i+1,mask,v,m,w);\n int flag=0;\n int sum=0;\n if(mask&1<<i){\n map<char, int> ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n\n bool check(string s ,unordered_map<char ,int>& map ){\n unordered_map<char,int> map2 ;\n for(int i = 0 ;i < s.length() ;i++ ){\n map2[s[i]]++;\n }\n for(auto x : map2){\n char c = x.first;\n int v = x.second;\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n\n bool check(string s ,unordered_map<char ,int>& map ){\n unordered_map<char,int> map2 ;\n for(int i = 0 ;i < s.length() ;i++ ){\n map2[s[i]]++;\n }\n for(auto x : map2){\n char c = x.first;\n int v = x.second;\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n map<string, int> scoreByWord;\n map<char, int> letterCount;\n for (char c: letters) {\n letterCount[c]++;\n }\n\n vector<string> possibleWords...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int helper(vector <string> &words,map <char,int> freq,vector <int>& score,int index,int currScore){\n if(index == words.size()){\n return currScore;\n }\n\n int ans = 0;\n\n //Not Take this\n ans = max(ans,helper(words,freq,score,...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\nint sol(string s1,unordered_map<char,int>m,vector<string>& w, vector<char>& l, vector<int>& s){\n int sc=0;\n unordered_map<char,int>m2;\n\n for(auto ch:s1){\n m2[ch]++;\n if(m[ch]>=m2[ch]){\n sc+=s[ch-'a'];\n if(m[ch]==0)m.erase(ch);\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int helper(vector<string>& words, int curr, vector<char> letters, vector<int>& score){\n\t\t//base case: there is no element\n if(curr<0)return 0;\n\t\t//using unordered_maps as they have better time complexity than normal map by a factor of log(N)\n unordered_...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int wrdScore(string s ,unordered_map<char, int> & letterScore , unordered_map<char, int>& freqMp ){\n int score = 0 ; \n for(int i = 0 ; i<s.size() ; i++){\n score+=letterScore[s[i]] ; \n freqMp[s[i]] -- ; \n }\n return score...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int wrdScore(string s ,unordered_map<char, int> & letterScore , unordered_map<char, int>& freqMp ){\n int score = 0 ; \n for(int i = 0 ; i<s.size() ; i++){\n score+=letterScore[s[i]] ; \n freqMp[s[i]] -- ; \n }\n return score...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n map <string,int> dp;\n int helper(vector <string> &words,map <char,int> freq,vector <int>& score,int index,int currScore){\n if(index == words.size()){\n return currScore;\n }\n\n int ans = 0;\n\n string key = \"\";\n auto it1 ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n map <string,int> dp;\n int helper(vector <string> &words,map <char,int> freq,vector <int>& score,int index,int currScore){\n if(index == words.size()){\n return currScore;\n }\n\n int ans = 0;\n\n string key = \"\";\n auto it1 ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\nint result=0;\n void solve(vector<string>&words,vector<char>& letters, vector<int>& score,int idx,map<int,int>mpp1,int s){\nif(idx>=words.size()){\n cout<<s<<endl;\nresult=max(result,s);\nreturn ;\n}\nint f=0;\nmap<int,int>wmpp;\nfor(int i=0;i<words[idx].size();i++){\n w...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\nint result=0;\n void solve(vector<string>&words,vector<char>& letters, vector<int>& score,int idx,map<int,int>mpp1,int s){\nif(idx>=words.size()){\n // cout<<s<<endl;\nresult=max(result,s);\nreturn ;\n}\nint f=0;\nmap<int,int>wmpp;\nfor(int i=0;i<words[idx].size();i++){\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(int ind,vector<string>& words, map<char,int> mpl,map<char,int>& mps)\n {\n if(ind==words.size()) return 0;\n string s=words[ind];\n map<char,int> mp; map<char,int> dummy; dummy=mpl;\n for(int i=0;i<s.size();i++) mp[s[i]]++;\n bool flag=fals...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int rec(vector<string>words, vector<int>score, int ans, map<char,int>count, int index){\n if(index == words.size()){\n return ans;\n }\n string w = words[index];\n int sum=0;\n map<char,int>temp = count;\n bool flag=true;\n...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters,\n vector<int>& score) {\n vector<pair<int, vector<int>>> v;\n\n for (int i = 0; i < words.size(); i++) {\n int sum = 0;\n vector<int> e(26);\n f...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\nbool is(string s,map<char,int>mp)\n{\n map<char,int>temp=mp;\n for(int i=0;i<s.size();i++)\n {\n if(temp[s[i]]<=0)return false;\n temp[s[i]]--;\n }\n\n return true;\n}\nint f(int ind,vector<string>& w, map<char,int>mp, vector<int>&score)\n{\n\n if(...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\nprivate:\n int maxScoreWordsHelper(int index, vector<string>& words, map<char, int> availableLetters, int curScore, map<string, int> &scoreMap,map<string, vector<int>> &anagramMap) {\n if (index == words.size()) {\n return curScore;\n }\n\n int dontTakeC...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\nprivate:\n int maxScoreWordsHelper(int index, vector<string>& words, map<char, int> availableLetters, int curScore, map<string, int> &scoreMap,map<string, vector<int>> &anagramMap, set<string>&best) {\n if (index == words.size()) {\n cout << \"Terminal Node: \" << cur...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n string al = \"abcdefghijklmnopqrstuvwxyz\";\n map <char , int> price;\n int cost[words.size() + 1];\n map <char , int> cnt;\n for ( int i = 0 ; i < 26 ; ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n string al = \"abcdefghijklmnopqrstuvwxyz\";\n map <char , int> price;\n int cost[words.size() + 1];\n map <char , int> cnt;\n for ( int i = 0 ; i < 26 ; ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n string al = \"abcdefghijklmnopqrstuvwxyz\";\n map <char , int> price;\n int cost[words.size() + 1];\n map <char , int> cnt;\n for ( int i = 0 ; i < 26 ; ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(int i,vector<string>& words,vector<int> v,vector<int>& score){\n if(i==words.size()){\n return 0;\n }\n int x=solve(i+1,words,v,score);\n int y=0;\n for(int j=0;j<words[i].size();j++){\n if(v[words[i][j]-'a']=...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n=words.size();\n vector<int> freq(128,0);\n for(auto it:letters){\n freq[it]++;\n } \n int ans=0;\n for(int i=0;i<(1<<n);i++){\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n multiset<char> letter(letters.begin(), letters.end());\n \n function<int(multiset<char>, int, int)> getAns = \n [&](multiset<char> charac, int fn_score, int...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n \n int findScore(vector<string> words, int conf, vector<int> charFreq, vector<int> scores){\n\n int res = 0;\n int i=0;\n cout<<conf<<endl;\n while(conf > 0){\n if(conf & 1){\n //cout<<words.size()<<\" \"<<i<<\" \"<<con...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n \n int findScore(vector<string> words, int conf, vector<int> charFreq, vector<int> scores){\n\n int res = 0;\n int i=0;\n //cout<<conf<<endl;\n while(conf > 0){\n if(conf & 1){\n //cout<<words.size()<<\" \"<<i<<\" \"<<c...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& a, vector<char>& letters, vector<int>& score) {\n \n int ans=0;\n int n=a.size();\n int mx= pow(2,n);\n \n for(int i=0;i<mx;i++)\n {\n vector<string> take;\n \n for(int j=0;j...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n void solve(vector<string>&s,int start,vector<string>&temp,\n vector<vector<string>>&ans)\n {\n if(start>=s.size())\n return;\n \n for(int i=start;i<s.size();i++)\n {\n temp.push_back(s[i]);\n ans.push_back(tem...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n unordered_map<char, int> umap;\n int n = words.size(), m = pow(2, n);\n int _max = INT_MIN;\n\n for (char l : letters)\n ++umap[l];\n \n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n unordered_map<char, int> umap;\n int n = words.size(), m = pow(2, n);\n int _max = INT_MIN;\n\n for (char l : letters)\n ++umap[l];\n \n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n \n unordered_map<char,int> mapa;\n for(int i=0;i<letters.size();i++)\n {\n mapa[letters[i]]++;\n }\n int ans=0;\n for(int i=0;i<...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "\nclass Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n unordered_map<char, int> letterCount;\n int maxsum = 0;\n int n = words.size();\n\n // Count frequency of each letter in 'letters'\n for (char e : lett...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int maxScore = INT_MIN;\n int n = words.size();\n int sz = (1 << n) - 1;\n unordered_map<char, int> hash;\n for(auto &ii : letters){\n hash[ii...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n cout.tie(0);\n int maxScore = INT_MIN;\n int n = words.size();\n int sz = (1 << n) - 1;\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <unordered_map>\n#include <algorithm>\n\nusing namespace std;\n\nclass Check {\npublic:\n bool valid = false;\n int ans = 0;\n};\n\nclass Obj {\npublic:\n string word;\n int wt = 0;\n};\n\nclass Ans {\npublic:\n int ans = 0;\n};\n\nclass Solut...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n unordered_map<char, int> letters_count;\n for (char c : letters) {\n letters_count[c]++;\n }\n\n int n = words.size();\n vector<unordered_map<char, int>> word_cou...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "#include <vector>\n#include <string>\n#include <unordered_map>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maxScore;\n vector<int> letterCount;\n vector<int> score;\n vector<vector<int>> wordLetterCount;\n unordered_map<string, int> memo;\n\n // Conver...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int f(int idx, vector<string>& words, vector<char>& letters, vector<int>& score, unordered_map<char, int> &mp) {\n if(idx == words.size()) return 0;\n\n // int hash = 0;\n // for (auto& pair : mp) {\n // hash = hash * 31 + stoi(pair.first) * 31...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(int i, vector<string>& words, vector<int>& score, unordered_map<char,int> &mp) {\n if(i==words.size()) return 0;\n\n int pick=0;\n unordered_map<char,int> temp;\n temp=mp;\n int sc=0;\n for(char ch: words[i]) {\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(int i, vector<string>& words, vector<int>& score, unordered_map<char,int> &mp) {\n if(i==words.size()) return 0;\n\n int pick=0;\n unordered_map<char,int> temp;\n temp=mp;\n int sc=0;\n for(char ch: words[i]) {\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(int i, vector<string>& words, vector<int>& score, unordered_map<char,int> &mp) {\n if(i==words.size()) return 0;\n\n int pick=0;\n unordered_map<char,int> temp;\n temp=mp;\n int sc=0;\n for(char ch: words[i]) {\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n = words.size(), k = 0, i, res = 0,j,x;\n for(i=0;i<n;i++) {\n k = k*2 + 1;\n }\n map<char, int> mp1, mp2, mp3;\n for(i=0;i<letters.size(...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n = words.size();\n map<char, int> freqM;\n for(char c: letters) freqM[c]++;\n map<char, int> scoreM;\n for(int i=0; i<26; ++i) scoreM['a' + i] = sco...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int solve(string &s,unordered_map<char,int>&m,vector<int>score){\n int ans=0;\n for(auto it:s){\n if(m[it]){\n ans+=score[it-'a'];\n m[it]--;\n }\n else{\n return 0;\n }\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n vector<int>ans(26,0);\n for(int i=0;i<score.size();i++){\n ans[i] = score[i];\n }\n map<char, int>mp;\n for(int i=0;i<letters.size();i++){\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n = words.size();\n int l = letters.size();\n map<char, int> m;\n for(int i=0; i<l; i++){\n m[letters[i]]++;\n }\n return solve(wor...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int getScore(int ind , vector<string>& words , unordered_map<int , int> &count ,vector<int>& score, int m ){\n if(ind >= m) return 0;\n unordered_map<int , int> copy = count ;\n string word = words[ind];\n int n = word.size();\n int sc = 0;\...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int getScore(int ind , vector<string>& words , unordered_map<int , int> &count ,vector<int>& score, int m ){\n if(ind >= m) return 0;\n unordered_map<int , int> copy = count ;\n //pick if possible \n string word = words[ind];\n int n = word...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\n void func(int indx, vector<string> words, vector<int> &score, int &ans,vector<int> &available_letters,vector<int> &required_letters){\n if(indx == words.size()){\n int curr_score=0;\n for(int i=0;i<26;i++){\n if(available_letters[i]<required...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n vector<string> subsets;\n int res = 0;\n void getSubsets(int index, vector<string> &words, string &s)\n {\n if(index >= words.size())\n {\n subsets.push_back(s);\n return;\n }\n string preString = s;\n getSubse...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<std::string>& words, vector<char>& letters, vector<int>& score) {\n\n vector<int> letterCount(26, 0);\n for(char ch : letters) {\n letterCount[ch - 'a']++;\n }\n\n\n auto calculateWordScore = [&](string& word, ve...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n bool canpick(string word,vector<int> tf){\n for(int i=0;i<word.size();i++){\n if(tf[word[i]-'a']==0) return 0;\n tf[word[i]-'a']--;\n }\n return 1;\n }\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<i...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n bool canpick(string word,vector<int> tf){\n for(int i=0;i<word.size();i++){\n if(tf[word[i]-'a']==0) return 0;\n tf[word[i]-'a']--;\n }\n return 1;\n }\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<i...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n\n int cal_score (vector<int>& score \n , string word ,vector<int> &freq_word_list)\n {\n int score_letter = 0 ; \n for (int i = 0 ; i < word.size() ; i++)\n {\n score_letter+= score[word[i]-'a'] ; \n\n freq_word_list[wor...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n = words.size();\n map<char, int> ml;\n for(char c: letters) {\n ml[c]++;\n }\n int ans = 0;\n for(int mask = 0; mask < (1LL << n)...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n bool isvalid(vector<string>& words, unordered_map<char, int> let_cnt, vector<int>& score, int& tmp_score){\n for(string word:words){\n for(char ch:word){\n if(let_cnt[ch]>=1){\n tmp_score+=score[ch-'a'];\n ...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\npublic:\n\n void f(int ind,int n,vector<string>&store,vector<string>&words,vector<vector<string>>&subset){\n if(ind==n){\n if(!store.empty())\n subset.push_back(store);\n return;\n }\n f(ind+1,n,store,words,subset);\n store.p...
1,381
<p>Given a list of <code>words</code>, list of&nbsp; single&nbsp;<code>letters</code> (might be repeating)&nbsp;and <code>score</code>&nbsp;of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two&nbsp;or ...
3
{ "code": "class Solution {\n void generateSubsets(vector<string>& words, int idx, vector<string>& temp, vector<vector<string>>& subsets){\n if(idx == words.size()){\n if(!temp.empty()){\n subsets.push_back(temp);\n }\n return;\n }\n\n temp.push_...