question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
minimum-number-of-people-to-teach
Is the expected I/O dataset wrong for this problem?
is-the-expected-io-dataset-wrong-for-thi-rn0a
Can anybody help me understand why is the answer for the following input be 4 instead of 3? \n\n\n17\n[[4,7,2,14,6],[15,13,6,3,2,7,10,8,12,4,9],[16],[10],[10,3
bridge_four
NORMAL
2021-01-23T16:39:56.504502+00:00
2021-01-23T16:39:56.504543+00:00
83
false
Can anybody help me understand why is the answer for the following input be `4` instead of `3`? \n\n```\n17\n[[4,7,2,14,6],[15,13,6,3,2,7,10,8,12,4,9],[16],[10],[10,3],[4,12,8,1,16,5,15,17,13],[4,13,15,8,17,3,6,14,5,10],[11,4,13,8,3,14,5,7,15,6,9,17,2,16,12],[4,14,6],[16,17,9,3,11,14,10,12,1,8,13,4,5,6],[14],[7,14],[1...
1
0
[]
1
minimum-number-of-people-to-teach
Java Solution
java-solution-by-abstracted_0507-710e
\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n int m = languages.length;\n boolean[][] kno
abstracted_0507
NORMAL
2021-01-23T16:34:26.424002+00:00
2021-01-23T16:34:26.424029+00:00
108
false
```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n int m = languages.length;\n boolean[][] knowsLang = new boolean[m][n];\n for(int i = 0; i < m; i++) {\n for(int j = 0; j < languages[i].length; j++) {\n knowsLang[i][l...
1
0
[]
1
minimum-number-of-people-to-teach
C++ O(n2logn) with tutorial
c-on2logn-with-tutorial-by-hawkings9999-z4gy
The Idea in this problem is the following, we have n langauges and there are m people and l pairs of people,\nwe need to find which langauge we need to make all
hawkings9999
NORMAL
2021-01-23T16:30:12.219175+00:00
2021-01-23T16:48:36.322661+00:00
210
false
The Idea in this problem is the following, we have n langauges and there are m people and l pairs of people,\nwe need to find which langauge we need to make all of them be able to talk to all the people that they are paired with. \nSome Observations,\nWe dont need to consider pair of people that have at least one langu...
1
1
[]
0
minimum-number-of-people-to-teach
C# Beats 100% Space/Time
c-beats-100-spacetime-by-rameshthaleia-b3qn
IntuitionUse bool arrays to simplify comparisons.Don't double-count a users language needs.Accumulate wanted languages when the user's can't speak.ApproachEach
rameshthaleia
NORMAL
2025-04-06T16:56:54.535866+00:00
2025-04-06T16:56:54.535866+00:00
1
false
# Intuition Use bool arrays to simplify comparisons. Don't double-count a users language needs. Accumulate wanted languages when the user's can't speak. # Approach Each user has a bool array indicating what languages they speak. Each user has a bool array indicating whether they have already requested a language or...
0
0
['C#']
0
minimum-number-of-people-to-teach
C# Beats 100% Space/Time
c-beats-100-spacetime-by-rameshthaleia-td2y
IntuitionUse dictionaries to simplify comparisons. Don't double-count a users language needs. Accumulate wanted languages when the user's can't speak.ApproachEa
rameshthaleia
NORMAL
2025-04-06T16:42:42.104831+00:00
2025-04-06T16:42:42.104831+00:00
2
false
# Intuition Use dictionaries to simplify comparisons. Don't double-count a users language needs. Accumulate wanted languages when the user's can't speak. # Approach Each user has a bool[n] indicating what languages they speak. Keep track of a user's wanted languages so we only count them once. Accumulates the wanted l...
0
0
['C#']
0
minimum-number-of-people-to-teach
While doing the program of minimum of teach two friends setup chars to use in the program
while-doing-the-program-of-minimum-of-te-gclq
IntuitionApproachComplexity Time complexity: Space complexity: Code
Girsha
NORMAL
2025-02-14T07:57:37.658081+00:00
2025-02-14T07:57:37.658081+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python']
0
minimum-number-of-people-to-teach
easy to understand, good for novice
easy-to-understand-good-for-novice-by-ji-cdty
Intuitionbrute force each language, see which one has the least people to teach.Complexity Time complexity: O(n*m)Code
jiayi9063
NORMAL
2025-02-06T21:06:02.883900+00:00
2025-02-06T21:06:02.883900+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> brute force each language, see which one has the least people to teach. # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> O(n*m) # Code ```python3 [] class Solution: def minimumTeachings(self, n: int,...
0
0
['Python3']
0
minimum-number-of-people-to-teach
1733. Minimum Number of People to Teach
1733-minimum-number-of-people-to-teach-b-zwtu
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-15T01:25:03.323300+00:00
2025-01-15T01:25:03.323300+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
minimum-number-of-people-to-teach
One language to rule them all
one-language-to-rule-them-all-by-tonitan-w2rl
IntuitionApproachComplexity Time complexity: O(n^2) Space complexity: Code
tonitannoury01
NORMAL
2024-12-19T18:56:37.024373+00:00
2024-12-19T18:56:37.024373+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n^2) - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```javascript [] /** * @param {number} n * @pa...
0
0
['JavaScript']
0
minimum-number-of-people-to-teach
brutforce solution with Sets
brutforce-solution-with-sets-by-debareto-zfnd
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
debareto
NORMAL
2024-10-31T14:58:20.356158+00:00
2024-10-31T14:58:20.356187+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python']
0
minimum-number-of-people-to-teach
Minimum Number Of People To Teach!!!
minimum-number-of-people-to-teach-by-sin-7n1o
\n\n# Code\njava []\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n //Step 1: Creating a map \n
sindhujadid_1804
NORMAL
2024-09-16T17:43:59.657825+00:00
2024-09-16T17:43:59.657853+00:00
28
false
\n\n# Code\n```java []\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n //Step 1: Creating a map \n // language --> person speaking\n HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();\n for(int i = 0; i < languages.length; i++){\...
0
0
['Array', 'Hash Table', 'Java']
0
minimum-number-of-people-to-teach
Very Easy Approach and Short Code in C++
very-easy-approach-and-short-code-in-c-b-i45g
Intuition and Approach\nstep1. find the total friends who can\'t comm. each other\nstep2.find the most comman lang btwn them\nstep3. ans=totalfriendsWhoCantComm
Akki2910
NORMAL
2024-09-02T05:05:56.157787+00:00
2024-09-02T05:05:56.157805+00:00
32
false
# Intuition and Approach\nstep1. find the total friends who can\'t comm. each other\nstep2.find the most comman lang btwn them\nstep3. ans=totalfriendsWhoCantComm-countOfMaximumComman Lang\n\n\nintuition:- if we know there are 10 people who cant comm. with each and maximum 5 of them know a comman language then minimum ...
0
0
['Greedy', 'C++']
0
minimum-number-of-people-to-teach
Hashing || C++
hashing-c-by-lotus18-xhbd
Code\n\nclass Solution \n{\npublic:\n int minimumTeachings(int lang, vector<vector<int>>& languages, vector<vector<int>>& friendships) \n {\n map<i
lotus18
NORMAL
2024-08-17T05:55:19.044081+00:00
2024-08-17T05:55:19.044113+00:00
8
false
# Code\n```\nclass Solution \n{\npublic:\n int minimumTeachings(int lang, vector<vector<int>>& languages, vector<vector<int>>& friendships) \n {\n map<int,set<int>> m;\n int n=languages.size();\n for(int x=0; x<n; x++)\n {\n set<int> st;\n for(auto it: languages[x...
0
0
['Hash Table', 'C++']
0
minimum-number-of-people-to-teach
Solution Minimum Number of People to Teach
solution-minimum-number-of-people-to-tea-2sqm
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Suyono-Sukorame
NORMAL
2024-07-02T06:45:28.968399+00:00
2024-07-02T06:45:28.968432+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['PHP']
0
minimum-number-of-people-to-teach
1733. Minimum Number of People to Teach.cpp
1733-minimum-number-of-people-to-teachcp-kyo3
Code\n\nclass Solution {\npublic:\n bool findCommon(vector<int>&a, vector<int>&b) {\n for(int i=0;i<a.size();i++) {\n for(int j=0;j<b.size(
202021ganesh
NORMAL
2024-06-10T09:05:34.467140+00:00
2024-06-10T09:05:34.467173+00:00
0
false
**Code**\n```\nclass Solution {\npublic:\n bool findCommon(vector<int>&a, vector<int>&b) {\n for(int i=0;i<a.size();i++) {\n for(int j=0;j<b.size();j++) {\n if(a[i]==b[j])\n return 1;\n }\n }\n return 0;\n } \n int minimumTeachings...
0
0
['C']
0
minimum-number-of-people-to-teach
Java HashMap
java-hashmap-by-abhinvsinh-l4r5
Intuition\n1. We need to find out which friends can already communicate so that we don\'t need to calculate the language teaching for them.\n2. For every langua
abhinvsinh
NORMAL
2024-06-01T06:49:05.415786+00:00
2024-06-01T06:49:05.415818+00:00
21
false
# Intuition\n1. We need to find out which friends can already communicate so that we don\'t need to calculate the language teaching for them.\n2. For every language , iterate through the friendship array and check if we need to teach the language to both the friends to be able to communicate.\n3. At the end , compare w...
0
0
['Java']
0
minimum-number-of-people-to-teach
O(M*N) Greedy solution using Set
omn-greedy-solution-using-set-by-vgvishe-k6q0
\n# Complexity\n- Time complexity:\nO(M*N)\n\n- Space complexity:\nO(M)\n\n# Code\n\nfunction minimumTeachings(n: number, languages: number[][], friendships: nu
vgvishesh
NORMAL
2024-05-19T04:14:20.446781+00:00
2024-05-19T04:14:20.446809+00:00
1
false
\n# Complexity\n- Time complexity:\nO(M*N)\n\n- Space complexity:\nO(M)\n\n# Code\n```\nfunction minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n function createFriendsLanguageSets() {\n let friendsLanguageSets: Set<number>[] = new Array(1);\n for (let i = 0; i < lang...
0
0
['TypeScript']
0
minimum-number-of-people-to-teach
3lines:
3lines-by-qulinxao-nnez
\n# Code\n\nclass Solution:\n def minimumTeachings(_, n: int, l: List[List[int]], f: List[List[int]]) -> int:\n q=set()\n for a,b in f: not set
qulinxao
NORMAL
2024-04-23T08:31:37.257521+00:00
2024-04-23T08:33:36.318259+00:00
19
false
\n# Code\n```\nclass Solution:\n def minimumTeachings(_, n: int, l: List[List[int]], f: List[List[int]]) -> int:\n q=set()\n for a,b in f: not set(l[a-1]).intersection(set(l[b-1]))and(q.add(a),q.add(b))\n return len(q)-(max(c.values())if ((c:=Counter()).update(chain.from_iterable((l[h-1]for h in...
0
0
['Union Find', 'Python3']
0
minimum-number-of-people-to-teach
Simple Intuitive Greedy (Beats 97% TE and 77% ME)
simple-intuitive-greedy-beats-97-te-and-pd276
Intuition\nIf people in a friendship are able to communicate with each other with at least 1 language, we do not care about them here.\nBut if they are not able
anushree97
NORMAL
2024-04-10T07:26:17.942832+00:00
2024-04-10T07:26:17.942864+00:00
23
false
# Intuition\nIf people in a friendship are able to communicate with each other with at least 1 language, we do not care about them here.\nBut if they are not able to communicate, we need to find the language which is most popular amoung this set and the number of speakers of that language. We will need to teach the oth...
0
0
['Greedy', 'Python3']
1
minimum-number-of-people-to-teach
Sol in Kotlin
sol-in-kotlin-by-arista_agarwal-r7f7
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Arista_agarwal
NORMAL
2024-03-02T04:59:10.409828+00:00
2024-03-02T04:59:10.409854+00:00
7
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Kotlin']
0
minimum-number-of-people-to-teach
Beats 100%, Hash Table, O(n + m)
beats-100-hash-table-on-m-by-igor0-cfkc
Intuition\nCreate a list of users\' pairs which need to learn a new language.\n\n# Approach\nAt first create new dictionary dicLang with a user as a key and a s
igor0
NORMAL
2024-02-28T22:30:23.694059+00:00
2024-02-28T22:37:27.850246+00:00
18
false
# Intuition\nCreate a list of users\' pairs which need to learn a new language.\n\n# Approach\nAt first create new dictionary `dicLang` with a user as a key and a set of user\'s languages as a value:\n```\nvar dicLang = CreateDicOfLanguages(languages);\n```\nThe create a list of users who need to learn a new language:\...
0
0
['Hash Table', 'C#']
0
minimum-number-of-people-to-teach
1733. Minimum Number of People to Teach
1733-minimum-number-of-people-to-teach-b-2idn
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
pgmreddy
NORMAL
2024-01-15T13:43:31.825001+00:00
2024-01-15T13:43:31.825039+00:00
14
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['JavaScript']
0
minimum-number-of-people-to-teach
Easy to understand JavaScript solution (Greedy)
easy-to-understand-javascript-solution-g-eyft
Complexity\n- Time complexity:\nO(mn)\n\n- Space complexity:\nO(mn)\n\n# Code\n\nvar minimumTeachings = function(n, languages, friendships) {\n const size =
tzuyi0817
NORMAL
2023-10-22T06:29:56.362543+00:00
2023-10-22T06:29:56.362564+00:00
14
false
# Complexity\n- Time complexity:\n$$O(mn)$$\n\n- Space complexity:\n$$O(mn)$$\n\n# Code\n```\nvar minimumTeachings = function(n, languages, friendships) {\n const size = languages.length;\n const communicate = Array(size).fill(\'\').map(_ => Array(n).fill(false));\n const users = new Set();\n let result = N...
0
0
['JavaScript']
0
minimum-number-of-people-to-teach
C++ | Commented
c-commented-by-jiahangli-slfn
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
JiahangLi
NORMAL
2023-10-11T15:21:10.112524+00:00
2023-10-11T15:21:10.112542+00:00
33
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
minimum-number-of-people-to-teach
C++
c-by-user5976fh-06em
\nclass Solution {\npublic:\n bool same(int a, int b, vector<vector<int>>& l){\n int i = 0, y = 0;\n while (i < l[a].size() && y < l[b].size())
user5976fh
NORMAL
2023-09-24T02:31:53.073038+00:00
2023-09-24T02:31:53.073057+00:00
6
false
```\nclass Solution {\npublic:\n bool same(int a, int b, vector<vector<int>>& l){\n int i = 0, y = 0;\n while (i < l[a].size() && y < l[b].size()){\n if (l[a][i] == l[b][y]) return true;\n else if (l[a][i] < l[b][y]) ++i;\n else ++y;\n }\n return false;\n ...
0
0
[]
0
minimum-number-of-people-to-teach
C++ Brute Force Solution
c-brute-force-solution-by-ranjan_him212-tmy7
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int ans = INT_MAX;\n
ranjan_him212
NORMAL
2023-09-20T08:04:11.751462+00:00
2023-09-20T08:04:11.751493+00:00
6
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int ans = INT_MAX;\n vector<set<int>> lang;\n set<int> stt;\n lang.push_back(stt);\n for(auto &x : languages)\n {\n set<int> st;\n ...
0
0
['C']
0
minimum-number-of-people-to-teach
C++ solution
c-solution-by-pejmantheory-2j25
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
pejmantheory
NORMAL
2023-09-01T04:00:20.209998+00:00
2023-09-01T04:00:20.210019+00:00
27
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
minimum-number-of-people-to-teach
good one
good-one-by-guventuncay-cf20
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
guventuncay
NORMAL
2023-06-25T16:05:12.063834+00:00
2023-06-25T16:05:12.063873+00:00
61
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Java']
0
minimum-number-of-people-to-teach
Space: O(m*n), Time: O(m*n)
space-omn-time-omn-by-iitjsagar-m80u
class Solution(object):\n def minimumTeachings(self, n, languages, friendships):\n """\n :type n: int\n :type languages: List[List[int]]
iitjsagar
NORMAL
2023-06-20T14:02:46.801555+00:00
2023-06-20T14:02:46.801579+00:00
35
false
class Solution(object):\n def minimumTeachings(self, n, languages, friendships):\n """\n :type n: int\n :type languages: List[List[int]]\n :type friendships: List[List[int]]\n :rtype: int\n """\n \n people = len(languages)+1\n \n lang_matrix = [[F...
0
0
['Graph']
0
minimum-number-of-people-to-teach
Java solution 70%
java-solution-70-by-valushaprogramist-1a94
Intuition\n Describe your first thoughts on how to solve this problem. \nThe most complicated part was to understand that it must be one language to solve every
ValushaProgramist
NORMAL
2023-06-19T21:44:49.659523+00:00
2023-06-19T21:44:49.659540+00:00
79
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe most complicated part was to understand that it must be one language to solve everything. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nI decided to create a map of zeros and ones to catch all teach events and...
0
0
['Array', 'Java']
0
minimum-number-of-people-to-teach
Python3 solution: logic + brute force
python3-solution-logic-brute-force-by-hu-o2ll
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst intuition was graph, because the problem was framed like a graph problem\n# Appro
huikinglam02
NORMAL
2023-05-31T05:41:34.091529+00:00
2023-05-31T05:41:34.091564+00:00
87
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst intuition was graph, because the problem was framed like a graph problem\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSince constraints are rather small, brute force trial and error would suffice\n# Complexi...
0
0
['Python3']
0
minimum-number-of-people-to-teach
C# Solution using Set || Easy To understand
c-solution-using-set-easy-to-understand-799q3
\n\npublic class Solution {\n public int MinimumTeachings(int n, int[][] languages, int[][] friendships) {\n HashSet<int> langsUnion = new HashSet<int
mohamedAbdelety
NORMAL
2023-04-29T14:09:54.576168+00:00
2023-04-29T14:09:54.576211+00:00
50
false
\n```\npublic class Solution {\n public int MinimumTeachings(int n, int[][] languages, int[][] friendships) {\n HashSet<int> langsUnion = new HashSet<int>();\n HashSet<int> diffSet = new HashSet<int>();\n foreach(var friend in friendships){\n int u = friend[0] - 1, v = friend[1] - 1;\...
0
0
['C#']
0
minimum-number-of-people-to-teach
Go clean code
go-clean-code-by-ythosa-ovx1
\n\nfunc minimumTeachings(n int, languages [][]int, friendships [][]int) int {\n\tvar cantSpeekPersons = make(map[int]struct{})\n\tfor _, friendship := range fr
ythosa
NORMAL
2023-04-28T00:12:28.488576+00:00
2023-04-28T00:12:28.488608+00:00
50
false
\n```\nfunc minimumTeachings(n int, languages [][]int, friendships [][]int) int {\n\tvar cantSpeekPersons = make(map[int]struct{})\n\tfor _, friendship := range friendships {\n\t\tfst := friendship[0] - 1\n\t\tsnd := friendship[1] - 1\n\t\tif !isLanguagesIntersects(languages, fst, snd) {\n\t\t\tcantSpeekPersons[fst] = ...
0
0
['Go']
0
minimum-number-of-people-to-teach
clean commented code
clean-commented-code-by-grumpyg-y8z8
the question is tricky to understand but easy to implement when you overcome that intial hurdle. \n\n\nclass Solution:\n def minimumTeachings(self, n: int, l
grumpyG
NORMAL
2023-03-29T21:33:05.011838+00:00
2023-03-29T21:33:05.011868+00:00
92
false
the question is tricky to understand but easy to implement when you overcome that intial hurdle. \n\n```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n # modify languages to be a set for quick intersection \n languages = {person...
0
0
['Python3']
0
minimum-number-of-people-to-teach
Just a runnable solution
just-a-runnable-solution-by-ssrlive-qavx
Code\n\nimpl Solution {\n pub fn minimum_teachings(n: i32, languages: Vec<Vec<i32>>, friendships: Vec<Vec<i32>>) -> i32 {\n fn check(a: &[Vec<i32>], u
ssrlive
NORMAL
2023-02-20T06:02:46.032580+00:00
2023-02-20T06:02:46.032625+00:00
50
false
# Code\n```\nimpl Solution {\n pub fn minimum_teachings(n: i32, languages: Vec<Vec<i32>>, friendships: Vec<Vec<i32>>) -> i32 {\n fn check(a: &[Vec<i32>], u: usize, v: usize, mem: &mut [Vec<i32>]) -> bool {\n if mem[u][v] != 0 {\n return mem[u][v] == 1;\n }\n for...
0
0
['Rust']
0
minimum-number-of-people-to-teach
Solution
solution-by-deleted_user-gamb
C++ []\nclass Solution {\nprivate:\n bool intersects(vector<int>& a, vector<int>& b, vector<bool>& vis){\n for(int elem: a){\n vis[elem] =
deleted_user
NORMAL
2023-02-03T07:28:57.463158+00:00
2023-03-08T08:15:42.190052+00:00
225
false
```C++ []\nclass Solution {\nprivate:\n bool intersects(vector<int>& a, vector<int>& b, vector<bool>& vis){\n for(int elem: a){\n vis[elem] = true;\n }\n\n bool intersectionFound = false;\n for(int elem: b){\n if(vis[elem]){\n intersectionFound = true;...
0
0
['C++', 'Java', 'Python3']
0
minimum-number-of-people-to-teach
Python short 3-line solution
python-short-3-line-solution-by-vincent_-ivlh
\ndef minimumTeachings(self, n: int, ls: List[List[int]], es: List[List[int]]) -> int:\n\tls = [{0}]+[set(i) for i in ls]\n\tns = reduce(ior, [{i, j} for i, j i
vincent_great
NORMAL
2023-01-22T13:17:23.287948+00:00
2023-01-22T13:19:20.952936+00:00
57
false
```\ndef minimumTeachings(self, n: int, ls: List[List[int]], es: List[List[int]]) -> int:\n\tls = [{0}]+[set(i) for i in ls]\n\tns = reduce(ior, [{i, j} for i, j in es if not ls[i]&ls[j]] or [{0}]) # ns=={0} means no teaching is needed\n\treturn min(sum(i not in ls[k] for k in ns) for i in range(1, n+1)) if len(ns)>1 e...
0
0
[]
0
minimum-number-of-people-to-teach
O(friendships * languages) time, O(number_of_people space)
ofriendships-languages-time-onumber_of_p-xmh1
Approach\nFirst check who are the people that have some unsatisfying friendship (have a friend that they can\'t speak with).\nnow among those people check what
sroninio
NORMAL
2023-01-10T12:04:36.435861+00:00
2023-01-10T12:04:36.435892+00:00
84
false
# Approach\nFirst check who are the $$people$$ that have some unsatisfying friendship (have a friend that they can\'t speak with).\nnow among those $$people$$ check what is the most popular language.\nthis is the language that needs to be taught to all the $$people$$ that dont know it.\n\n\n# Code\n```\nclass Solution(...
0
0
['Python']
0
minimum-number-of-people-to-teach
Python(Simple Maths)
pythonsimple-maths-by-rnotappl-ekgg
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
rnotappl
NORMAL
2022-12-19T15:45:50.346432+00:00
2022-12-19T15:45:50.346471+00:00
171
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
minimum-number-of-people-to-teach
Java solution intuitive
java-solution-intuitive-by-jeshupatelg37-t4ns
\n\n# Code\n\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n ArrayList<HashSet<Integer>> lan = new
jeshupatelg3774
NORMAL
2022-12-18T21:15:58.874460+00:00
2022-12-18T21:15:58.874501+00:00
190
false
\n\n# Code\n```\nclass Solution {\n public int minimumTeachings(int n, int[][] languages, int[][] friendships) {\n ArrayList<HashSet<Integer>> lan = new ArrayList<>();\n for(int i =0;i<languages.length;i++){//converting languages array to list of set for easy search\n lan.add(new HashSet<>()...
0
0
['Java']
0
minimum-number-of-people-to-teach
[JavaScript] Clean Solution
javascript-clean-solution-by-cucla101-ru1l
Code\n\n\n\nlet minimumTeachings = function(n, languages, friendships) {\n let mostSpokenLanguages = new Array(n + 1).fill(0);\n let PPL = new Map
cucla101
NORMAL
2022-12-07T20:42:57.881922+00:00
2022-12-07T20:44:43.025561+00:00
127
false
# Code\n\n```\n\nlet minimumTeachings = function(n, languages, friendships) {\n let mostSpokenLanguages = new Array(n + 1).fill(0);\n let PPL = new Map();\n\n friendships.forEach( ( element ) => \n {\n let LANG = new Set( languages[element[0] - 1] );\n\n let shareLang =...
0
0
['JavaScript']
0
minimum-number-of-people-to-teach
[Python] - Commented and Simple Python Solution
python-commented-and-simple-python-solut-a0ho
Intuition\n Describe your first thoughts on how to solve this problem. \nI think this problem is in the harder range of medium problems.\n\nThere are some thing
Lucew
NORMAL
2022-12-01T11:10:09.141381+00:00
2022-12-01T11:10:09.141407+00:00
114
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI think this problem is in the harder range of medium problems.\n\nThere are some things you need to consider:\n1) We only deal with users that are disconnected from other users\n2) We need to keep track of the most common known language ...
0
0
['Python3']
0
minimum-number-of-people-to-teach
C++ solution with explanation
c-solution-with-explanation-by-slothalan-4108
So, the question statement shall be paraphrased as follows:\n\nFind the minimum number of users to learn a new language L, such that for each pair of immediate
slothalan
NORMAL
2022-11-29T13:53:51.982272+00:00
2022-11-29T13:53:51.982317+00:00
54
false
So, the question statement shall be paraphrased as follows:\n\nFind the minimum number of users to learn a new language L, such that *for each pair of immediate friends (**no** nested relationships...), they don\'t have a common language, but each of them may or may not have learned L.*\n\n(-_-)\n\n```cpp\nclass Soluti...
0
0
[]
0
minimum-number-of-people-to-teach
python greedy solution
python-greedy-solution-by-alston16-e7nh
\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n counter = [set() for i in r
ALSTON16
NORMAL
2022-11-12T04:15:52.259794+00:00
2022-11-12T04:15:52.259847+00:00
31
false
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n counter = [set() for i in range(len(languages))]\n memo = dict()\n for i in range(len(languages)):\n for j in languages[i]:\n counter[i].add(j)\...
0
0
[]
0
minimum-number-of-people-to-teach
[C++] |Simple|Easy to read and Unerstand
c-simpleeasy-to-read-and-unerstand-by-en-pe9c
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m=languages.size()
endless_mercury
NORMAL
2022-11-02T16:56:04.891779+00:00
2022-11-02T16:56:04.891820+00:00
74
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m=languages.size();\n //keep track if person can speak language already\n vector<vector<bool>> can_speak(m+1,vector<bool>(n+1,false));\n for(int i=0;i<m;i...
0
0
['C']
0
minimum-number-of-people-to-teach
Python 3 Solution
python-3-solution-by-aryaman73-nluj
\nIndexing is a bit annoying, since everything is 1-indexed, so keep that in mind. \n\npy\nclass Solution:\n def minimumTeachings(self, n: int, languages: Li
aryaman73
NORMAL
2022-10-17T03:30:41.589871+00:00
2022-10-17T03:30:41.589917+00:00
110
false
\nIndexing is a bit annoying, since everything is 1-indexed, so keep that in mind. \n\n```py\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n \n # Find which friendships can not communicate, i.e. which users need to be taught\n ...
0
0
['Python']
0
minimum-number-of-people-to-teach
Use sets to get friends who can't communicate
use-sets-to-get-friends-who-cant-communi-dy9x
\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n hmap = {}\n for i, l
rktayal
NORMAL
2022-09-27T02:25:31.241925+00:00
2022-09-27T02:25:31.241966+00:00
40
false
```\nclass Solution:\n def minimumTeachings(self, n: int, languages: List[List[int]], friendships: List[List[int]]) -> int:\n hmap = {}\n for i, l_list in enumerate(languages):\n hmap[i+1] = set()\n for item in l_list:\n hmap[i+1].add(item)\n \n mis_fr...
0
0
['Ordered Set', 'Python']
0
minimum-number-of-people-to-teach
Confusion
confusion-by-zsun273-6bch
For this example, why is the answer 3?\n\n4\n[[1],[2],[3],[4]]\n[[1,2],[3,4]]\n\nwe can simply teach 1 language 2 and teach 3 language 4, which leads to answer
zsun273
NORMAL
2022-09-20T19:25:15.429202+00:00
2022-09-20T19:25:15.429241+00:00
22
false
For this example, why is the answer 3?\n\n4\n[[1],[2],[3],[4]]\n[[1,2],[3,4]]\n\nwe can simply teach 1 language 2 and teach 3 language 4, which leads to answer 2.
0
0
[]
0
minimum-number-of-people-to-teach
[Time & Memory 100%] Try all languages and find minimum
time-memory-100-try-all-languages-and-fi-rpov
Complexity\nTime: O(m * n)\nSpace: O(m * n)\n\ntypescript\nfunction minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n /
jhw123
NORMAL
2022-08-30T09:11:51.520803+00:00
2022-08-30T09:11:51.520849+00:00
70
false
### Complexity\nTime: `O(m * n)`\nSpace: `O(m * n)`\n\n```typescript\nfunction minimumTeachings(n: number, languages: number[][], friendships: number[][]): number {\n // filter the friends who do not have a common language and need to be taught\n\tconst friendshipsWithProblem = []\n for (const [f1, f2] of friends...
0
0
['Ordered Set', 'TypeScript', 'JavaScript']
0
minimum-number-of-people-to-teach
C++, filter friendships, 100%
c-filter-friendships-100-by-cx3129-001a
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m=languages.size()
cx3129
NORMAL
2022-06-05T10:48:40.935142+00:00
2022-06-05T10:59:54.473877+00:00
112
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) {\n int m=languages.size();\n vector<vector<bool>> hasLan(m+1,vector<bool>(n+1,false)); //cache for which languages each user known\n for(int i=1;i<=m;++i) \n ...
0
0
[]
0
minimum-number-of-people-to-teach
[C++] || Set,Map
c-setmap-by-rahul921-x45n
\nclass Solution {\npublic:\n set<int> cantTalk ;\n bool InCommon(vector<int>& lang1 , vector<int>&lang2 ){\n //checks if two friends can speak an
rahul921
NORMAL
2022-05-27T08:30:09.095518+00:00
2022-05-27T08:30:09.095559+00:00
180
false
```\nclass Solution {\npublic:\n set<int> cantTalk ;\n bool InCommon(vector<int>& lang1 , vector<int>&lang2 ){\n //checks if two friends can speak any language in common ?\n for(auto &x : lang1)\n for(auto &y : lang2)\n if(x == y) return true ;\n \n \n ...
0
0
['C']
0
minimum-number-of-people-to-teach
Intersection of common languages
intersection-of-common-languages-by-ttn6-yiq8
Very unclear description, I must say...\nBut not a bad question after all.\n\ncpp\n// check if user u and v share a common language.\n// sorted array and two-po
ttn628826
NORMAL
2022-05-21T12:46:50.598397+00:00
2022-05-21T12:51:19.985851+00:00
108
false
Very unclear description, I must say...\nBut not a bad question after all.\n\n```cpp\n// check if user u and v share a common language.\n// sorted array and two-pointer, \n// binary search might be even better.\nbool haveCommon(vector<vector<int>>& lan, int u, int v)\n{\n\tint i = 0;\n\tint j = 0;\n\t\n\twhile (i < lan...
0
0
['C']
0
minimum-number-of-people-to-teach
93% Time and 89% Space, 277 ms Simple Logic Explained
93-time-and-89-space-277-ms-simple-logic-2jj0
```\nclass Solution {\npublic:\n #define pii pair\n #define f first\n #define s second\n int minimumTeachings(int n, vector>& langs, vector>& conn)
ms2000
NORMAL
2022-05-21T04:35:58.870046+00:00
2022-05-21T04:39:11.032535+00:00
74
false
```\nclass Solution {\npublic:\n #define pii pair<int,int>\n #define f first\n #define s second\n int minimumTeachings(int n, vector<vector<int>>& langs, vector<vector<int>>& conn) {\n \n vector<int> allLang(n+1,0);\n int m = conn.size();\n vector<pii> graph;\n int mx = 0;...
0
0
[]
0
minimum-number-of-people-to-teach
Scala
scala-by-fairgrieve-q2nc
\nimport scala.collection.immutable.BitSet\nimport scala.util.chaining.scalaUtilChainingOps\n\nobject Solution {\n def minimumTeachings(n: Int, languages: Arra
fairgrieve
NORMAL
2022-04-04T05:17:42.591734+00:00
2022-04-04T05:17:42.591771+00:00
38
false
```\nimport scala.collection.immutable.BitSet\nimport scala.util.chaining.scalaUtilChainingOps\n\nobject Solution {\n def minimumTeachings(n: Int, languages: Array[Array[Int]], friendships: Array[Array[Int]]): Int = {\n languages\n .map(_.to(BitSet))\n .pipe { languages =>\n friendships\n ...
0
0
['Scala']
0
minimum-number-of-people-to-teach
count for friends without same language c++
count-for-friends-without-same-language-67atg
\nclass Solution {\n bool hassame(const vector<int>& v1, const vector<int>& v2)\n {\n int i1=0, i2=0;\n while(i1<v1.size() && i2<v2.size())\
dolaamon2
NORMAL
2022-04-02T13:47:03.670331+00:00
2022-04-02T13:49:45.537020+00:00
78
false
```\nclass Solution {\n bool hassame(const vector<int>& v1, const vector<int>& v2)\n {\n int i1=0, i2=0;\n while(i1<v1.size() && i2<v2.size())\n {\n if (v1[i1] == v2[i2])\n return true;\n else if (v1[i1] < v2[i2])\n i1++;\n else\n...
0
0
[]
0
minimum-number-of-people-to-teach
Java solution with explanation
java-solution-with-explanation-by-ptdao-jdn5
\n\nclass Solution {\n \n /**\n Algorithm:\n\n 1. We will initialize the variable \'minimumUsers\' = total users, and it will store the minimum
ptdao
NORMAL
2022-03-22T00:05:14.364621+00:00
2022-03-22T00:05:14.364721+00:00
112
false
\n```\nclass Solution {\n \n /**\n Algorithm:\n\n 1. We will initialize the variable \'minimumUsers\' = total users, and it will store the minimum number of users that needs to learn the common language.\n 2. Maintain a user Map, which stores users who cannot communicate with their friends.\n ...
0
0
[]
0
minimum-number-of-people-to-teach
Golang | O(N * Len(FriendShip) | Bitset, SIMD, Loop Unroll | Beat 100%
golang-on-lenfriendship-bitset-simd-loop-hesr
\nfunc minimumTeachings(n int, langs [][]int, friends [][]int) int {\n m := len(langs)\n \n set := make([][8]uint64, m)\n for i, lang := range langs
linhduong
NORMAL
2021-12-13T13:45:54.918861+00:00
2021-12-13T13:46:17.193654+00:00
242
false
```\nfunc minimumTeachings(n int, langs [][]int, friends [][]int) int {\n m := len(langs)\n \n set := make([][8]uint64, m)\n for i, lang := range langs {\n for _, l := range lang {\n set[i] = turnOn(set[i], l - 1)\n } \n }\n \n added := make([]bool, m)\n \n min := m+1\...
0
0
['Go']
0
minimum-number-of-people-to-teach
[Golang] Two steps brute force solution
golang-two-steps-brute-force-solution-by-tut9
Get the people who need learn other language then store in a map.\n2. Check the number of people need to learn if teaching them from language "1" to "n". \nThe
genius52
NORMAL
2021-12-03T05:25:01.966280+00:00
2021-12-03T05:25:36.537438+00:00
95
false
1. Get the people who need learn other language then store in a map.\n2. Check the number of people need to learn if teaching them from language "1" to "n". \nThe minimum number is we need.\n```\nfunc minimumTeachings(n int, languages [][]int, friendships [][]int) int {\n\tvar need_learn_people map[int]bool = make(map[...
0
0
['Go']
0
minimum-number-of-people-to-teach
C# 100%
c-100-by-rahulvn389-rwnx
public class Solution {\n \n private bool CanCommunicate(int[][] languages, int a, int b)\n {\n var languagesA = languages[a-1];\n var la
rahulvn389
NORMAL
2021-11-02T19:02:38.919863+00:00
2021-11-02T19:02:38.919899+00:00
58
false
public class Solution {\n \n private bool CanCommunicate(int[][] languages, int a, int b)\n {\n var languagesA = languages[a-1];\n var languagesB = languages[b-1];\n \n int i=0;\n int j=0;\n while(i<languagesA.Length && j<languagesB.Length)\n {\n if(l...
0
0
[]
0
minimum-number-of-people-to-teach
c++ | bitset
c-bitset-by-_seg_fault-pueq
Idea\nFor every person who can\'t talk with its friend, store which language he/she needs to be taught and store the frequency of that language in an array toTe
_seg_fault
NORMAL
2021-09-08T09:27:39.655978+00:00
2021-09-08T09:27:55.897171+00:00
115
false
<b>Idea</b>\nFor every person who can\'t talk with its friend, store which language he/she needs to be taught and store the frequency of that language in an array `toTeach`. The language that needs to be taught to minimum number of people is the desired one. \nNote: In order to ensure that the same person to be taught ...
0
0
[]
0
minimum-number-of-people-to-teach
[100% Solution] Concise Solution speeding up with bitmap + Cpp Code
100-solution-concise-solution-speeding-u-3oab
\nRuntime: 120 ms, faster than 100.00% of C++ online submissions \nMemory Usage: 59.2 MB, less than 98.82% of C++ online submissions\n\nWe have N languages and
mkyang
NORMAL
2021-08-31T10:49:05.158840+00:00
2021-08-31T10:50:46.300189+00:00
181
false
```\nRuntime: 120 ms, faster than 100.00% of C++ online submissions \nMemory Usage: 59.2 MB, less than 98.82% of C++ online submissions\n```\nWe have N languages and M persons. Let us image that we have a MxN table "L".\n```\nL[m][n] = 1 means the person m knows the languag n, and 0 means opposite.\n```\nIf two people ...
0
0
[]
0
minimum-number-of-people-to-teach
C++ | unordered_set
c-unordered_set-by-sonusharmahbllhb-9q44
\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& lng, vector<vector<int>>& frnd) {\n unordered_set<int> unc;\n in
sonusharmahbllhb
NORMAL
2021-08-28T07:09:35.944265+00:00
2021-08-28T07:09:35.944307+00:00
336
false
```\nclass Solution {\npublic:\n int minimumTeachings(int n, vector<vector<int>>& lng, vector<vector<int>>& frnd) {\n unordered_set<int> unc;\n int lsz=lng.size();\n int fsz=frnd.size();\n vector<unordered_set<int>> v(lsz+1);\n for(int i=0;i<lsz;i++){\n unordered_set<int...
0
0
['C', 'C++']
0
minimum-number-of-people-to-teach
JavaScript faster than 100%
javascript-faster-than-100-by-lilongxue-wouw
\n/**\n * @param {number} n\n * @param {number[][]} languages\n * @param {number[][]} friendships\n * @return {number}\n */\nvar minimumTeachings = function(n,
lilongxue
NORMAL
2021-07-17T12:03:57.245319+00:00
2021-07-17T12:03:57.245366+00:00
110
false
```\n/**\n * @param {number} n\n * @param {number[][]} languages\n * @param {number[][]} friendships\n * @return {number}\n */\nvar minimumTeachings = function(n, languages, friendships) {\n // user count\n const len = languages.length\n function Node(val) {\n \n }\n Node.table = new Array(1 + len...
0
0
[]
0
sum-of-prefix-scores-of-strings
[C++, Java, Python3] Easy Trie Explained with diagram
c-java-python3-easy-trie-explained-with-52svp
\n\nWe construct a trie to find the number of times each node has been visited.\n\nIterate over ["abc","ab","bc","b"] and the trie looks like:\n\n\n After const
tojuna
NORMAL
2022-09-18T04:01:13.157566+00:00
2022-09-18T04:23:38.390015+00:00
9,979
false
\n\nWe construct a trie to find the number of times each node has been visited.\n\nIterate over `["abc","ab","bc","b"]` and the trie looks like:\n![image](https://assets.leetcode.com/users/images/6f8b9a77-e532-400a-8a61-e14a5eec57c9_1663473172.2202284.png)\n\n* After constructing the `trie` we just iterate over the giv...
105
1
[]
13
sum-of-prefix-scores-of-strings
Simple step by step solution using Trie data structure
simple-step-by-step-solution-using-trie-nyto0
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem can be effectively solved using a Trie (prefix tree) data structure. The Tr
Reddaiah12345
NORMAL
2024-09-25T02:44:19.606444+00:00
2024-09-25T02:44:19.606488+00:00
14,796
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem can be effectively solved using a Trie (prefix tree) data structure. The Trie structure allows us to efficiently store and traverse the prefixes of words. Each node in the Trie keeps track of how many times a particular prefix...
88
3
['Array', 'String', 'Trie', 'Counting', 'C++', 'Java', 'Python3']
7
sum-of-prefix-scores-of-strings
C++ | Trie | Related Problems
c-trie-related-problems-by-kiranpalsingh-kdf6
Store each string in trie and add 1 to each prefix of string while inserting.\n- Then, for each string, we sum up the count for all its prefixes.\n\n\n\ncpp\nst
kiranpalsingh1806
NORMAL
2022-09-18T04:01:16.143848+00:00
2022-09-19T05:21:10.853388+00:00
5,459
false
- Store each string in trie and **add 1 to each prefix of string while inserting**.\n- Then, for each string, **we sum up the count for all its prefixes**.\n![image](https://assets.leetcode.com/users/images/fde5fc03-7578-4e5f-91e4-570837f1057a_1663474247.6931121.png)\n\n\n```cpp\nstruct TrieNode {\n TrieNode *next[2...
68
2
['Trie', 'C']
13
sum-of-prefix-scores-of-strings
[Python] Explanation with pictures, 2 solutions
python-explanation-with-pictures-2-solut-f21p
Solution 1. Counter of prefix\n\nUse counter C to collect every prefix of every word. \nThen sum up C[pre] for every prefix pre of word word, this is the score
Bakerston
NORMAL
2022-09-18T04:01:58.958795+00:00
2022-09-18T04:40:03.144501+00:00
2,676
false
### Solution 1. Counter of prefix\n\nUse counter `C` to collect every prefix of every word. \nThen sum up `C[pre]` for every prefix `pre` of word `word`, this is the score of `word`.\n\n**python**\n\n```\nclass Solution:\n def sumPrefixScores(self, W: List[str]) -> List[int]:\n C = collections.defaultdict(int...
52
0
[]
11
sum-of-prefix-scores-of-strings
Full Dry Run + Brute to Trie Explained, illustrations || Let's Go !!
full-dry-run-brute-to-trie-explained-ill-buzx
Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/Sh0ca33JjMM?si=9tzS3AuxGtHSgkew\n\n# Intuition
Rarma
NORMAL
2024-09-25T02:11:13.740855+00:00
2024-09-25T11:53:02.876888+00:00
6,309
false
# Youtube Explanation\nSoon to be on Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\nhttps://youtu.be/Sh0ca33JjMM?si=9tzS3AuxGtHSgkew\n\n# Intuition & Approach\n\n> If you don\'t know trie, don\'t worry this article will help you get an idea about how it works.\n\n![image.png](https://assets.leetcode.com/u...
30
0
['Array', 'String', 'Trie', 'String Matching', 'Counting', 'C++', 'Java']
5
sum-of-prefix-scores-of-strings
[Python3] Simple trie O (n*k) with line by line comments.
python3-simple-trie-o-nk-with-line-by-li-5moe
The idea is to use trie. When initializing the trie, instead of storing the end of the word, we are tracking the number of times this prefix has occurred.\nOnce
MeidaChen
NORMAL
2022-09-18T04:02:09.029154+00:00
2024-01-04T19:26:05.006558+00:00
1,211
false
The idea is to use trie. When initializing the trie, instead of storing the end of the word, we are tracking the number of times this prefix has occurred.\nOnce we have the trie, we will go through all the words one more time and count how many times its prefix has occurred to build our result.\n\n```\nclass Solution:\...
24
0
[]
3
sum-of-prefix-scores-of-strings
Trie
trie-by-votrubac-75g6
\nFirst, we add all strings into a Trie, incrementing the count for each prefix.\n \nThen, for each string, we aggregate the count for all its prefixes. \n
votrubac
NORMAL
2022-09-18T04:01:59.754053+00:00
2022-09-18T04:01:59.754098+00:00
2,401
false
\nFirst, we add all strings into a Trie, incrementing the count for each prefix.\n \nThen, for each string, we aggregate the count for all its prefixes. \n \n**C++**\n```cpp\nstruct Trie {\n Trie* ch[26] = {};\n int cnt = 0;\n void insert(string &w, int i = 0) {\n auto n = this;\n for (auto...
23
0
[]
7
sum-of-prefix-scores-of-strings
Trie Solution || O(N*k) || Beats 97% || C++ || Python
trie-solution-onk-beats-97-c-python-by-r-yy7a
Intuition\n Describe your first thoughts on how to solve this problem. \nUse a datastructure that allows quick prefix count\n\n# Approach\n Describe your approa
Rzhek
NORMAL
2024-09-25T00:10:46.634229+00:00
2024-09-25T00:24:56.447120+00:00
11,220
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse a datastructure that allows quick prefix count\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Add each word to a trie\n- Increment score of nodes while adding words (except root node)\n- Run DFS for each wor...
22
0
['String', 'Trie', 'C++', 'Python3']
8
sum-of-prefix-scores-of-strings
trie, java
trie-java-by-clasiqh-vtsy
Code:\n\n Node root = new Node(); // Trie root.\n class Node {\n int score = 0;\n Node[] child = new Node[26];\n }\n \n public int
clasiqh
NORMAL
2022-09-18T04:00:32.785885+00:00
2022-09-18T04:22:45.741052+00:00
1,668
false
**Code:**\n\n Node root = new Node(); // Trie root.\n class Node {\n int score = 0;\n Node[] child = new Node[26];\n }\n \n public int[] sumPrefixScores(String[] words) {\n for(String word : words) add(word); // make trie.\n \n int [] res = new int[words.length];\n ...
21
2
['Trie', 'Java']
1
sum-of-prefix-scores-of-strings
Trie again
trie-again-by-anwendeng-qesq
Intuition\n Describe your first thoughts on how to solve this problem. \nUse Trie with memeber variable len\n# Approach\n Describe your approach to solving the
anwendeng
NORMAL
2024-09-25T02:56:44.580955+00:00
2024-09-25T02:56:44.580973+00:00
1,171
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse Trie with memeber variable len\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Define Trie struct with construtor, insert methods.\n2. In solution, let `trie` be the memeber variable.\n3. Define a member metho...
16
0
['Array', 'String', 'Trie', 'Counting', 'C++']
7
sum-of-prefix-scores-of-strings
[C++] Detailed Explanation w/ Diagram | Easy and commented code | Simple language
c-detailed-explanation-w-diagram-easy-an-z9cd
IDEA:\n We store each word of the words array in the trie.\n Every Node of the trie contains two arrays of size 26.\n First array denotes the characters of engl
aryanttripathi
NORMAL
2022-09-18T07:51:37.586428+00:00
2022-09-18T07:51:37.586473+00:00
1,206
false
**IDEA:**\n* We store each word of the words array in the trie.\n* Every Node of the trie contains two arrays of size 26.\n* First array denotes the characters of english alphabets i.e index 0 denotes character \'a\', index 1 denotes character \'b\'... like this.\n* Second array number denotes how many number of times ...
16
2
['C']
2
sum-of-prefix-scores-of-strings
Python | Trie-based Pattern
python-trie-based-pattern-by-khosiyat-s5cx
see the Successfully Accepted Submission\n\n# Code\npython3 []\nclass TrieNode:\n def __init__(self):\n self.children = {}\n self.prefix_count
Khosiyat
NORMAL
2024-09-25T01:42:27.827759+00:00
2024-09-25T01:42:27.827791+00:00
1,175
false
[see the Successfully Accepted Submission](https://leetcode.com/problems/sum-of-prefix-scores-of-strings/submissions/1401354774/?envType=daily-question&envId=2024-09-25)\n\n# Code\n```python3 []\nclass TrieNode:\n def __init__(self):\n self.children = {}\n self.prefix_count = 0\n\nclass Solution:\n ...
13
0
['Python3']
3
sum-of-prefix-scores-of-strings
Trie || Beats 97% || C++ || Python || Java
trie-beats-97-c-python-java-by-as_313-mxrh
Intuition\nThe goal of the problem is to calculate the total score of every non-empty prefix of each word in a given list of strings. The score of a prefix is d
Baslik69
NORMAL
2024-09-25T00:33:38.060780+00:00
2024-09-25T00:33:38.060814+00:00
3,920
false
# Intuition\nThe goal of the problem is to calculate the total score of every non-empty prefix of each word in a given list of strings. The score of a prefix is defined as the number of strings in the list that start with that prefix.\n\nTo solve this efficiently, we can use a Trie (prefix tree) data structure. The Tri...
13
1
['Array', 'String', 'Trie', 'Counting', 'Python', 'C++', 'Java', 'Python3']
1
sum-of-prefix-scores-of-strings
Thought process explained | Trie | For beginner
thought-process-explained-trie-for-begin-pigq
So First question?\n How I got to know that Trie will work.\n\t So let\'s thing :\n\t We have 1000 words of 1000 length each. Also we have to get the value for
faltu_admi
NORMAL
2022-09-18T04:02:38.666712+00:00
2022-09-18T04:02:38.666754+00:00
578
false
## So First question?\n* How I got to know that Trie will work.\n\t* So let\'s thing :\n\t* We have 1000 words of 1000 length each. Also we have to get the value for substring also.\n\t\t* Will HashMap works? No because for 1k word of 1k length, going to store all substring that would cause TLE.\n\t* So let\'s think so...
12
0
[]
2
sum-of-prefix-scores-of-strings
⚙ C++ || NO TRIE || NLOGN SOLUTION
c-no-trie-nlogn-solution-by-venom-xd-frvr
\t\tclass Solution {\n\t\tpublic:\n\t\t\tvector sumPrefixScores(vector& words) {\n\t\t\t\tint n = words.size();\n\t\t\t\tvector> words2;\n\t\t\t\tfor (int i = 0
venom-xd
NORMAL
2022-09-18T04:31:12.435990+00:00
2022-09-18T04:31:12.436041+00:00
1,302
false
\t\tclass Solution {\n\t\tpublic:\n\t\t\tvector<int> sumPrefixScores(vector<string>& words) {\n\t\t\t\tint n = words.size();\n\t\t\t\tvector<pair<string, int>> words2;\n\t\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\t\twords2.push_back(make_pair(words[i], i));\n\t\t\t\t}\n\t\t\t\tsort(words2.begin(), words2.end());\n\n\...
10
0
['Trie', 'C', 'C++', 'Java']
1
sum-of-prefix-scores-of-strings
C# Solution for Sum of Prefix Scores of Strings Problem
c-solution-for-sum-of-prefix-scores-of-s-26iq
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires us to compute the score of each word in an array, where the score
Aman_Raj_Sinha
NORMAL
2024-09-25T02:52:36.987948+00:00
2024-09-25T02:52:36.987984+00:00
235
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires us to compute the score of each word in an array, where the score is the sum of how many words have each prefix of the word. A brute force approach (checking each prefix of each word against all other words) would be ...
9
0
['C#']
0
sum-of-prefix-scores-of-strings
🌟 [Explained]🔍 From Brute Force to Tries: 🚀 Mastering Sum Of Prefix Scores Optimization 🌟
explained-from-brute-force-to-tries-mast-ub2r
\n# Approach 1: Brute Force (Memory Limit Exceeded - MLE) \uD83D\uDED1\nThis approach uses a brute-force method by storing each word\'s prefixes in a map with v
AlgoArtisan
NORMAL
2024-09-25T02:24:05.494606+00:00
2024-09-25T04:47:36.811546+00:00
1,436
false
\n# Approach 1: Brute Force (Memory Limit Exceeded - MLE) \uD83D\uDED1\nThis approach uses a brute-force method by storing each word\'s prefixes in a map with vector<string>. For every prefix, the corresponding vector stores all occurrences of the prefix, leading to an excessive memory footprint.\n\n# Time Complexity:\...
9
0
['Hash Table', 'String', 'Trie', 'C++']
3
sum-of-prefix-scores-of-strings
[Python] Trie Solution
python-trie-solution-by-lee215-ceji
Explanation\nUse Trie to build up a tree.\nadd word and add 1 point to each node on the word path.\nsocre will sum up the point on the word path.\n\n\n# Complex
lee215
NORMAL
2022-09-18T04:06:02.757623+00:00
2022-09-19T16:26:38.776881+00:00
555
false
# **Explanation**\nUse Trie to build up a tree.\n`add` word and add `1` point to each node on the word path.\n`socre` will sum up the point on the word path.\n<br>\n\n# **Complexity**\nTime `O(words)`\nSpace `O(words)`\n<br>\n\n\n**Python**\n```py\nclass Trie(object):\n\n def __init__(self):\n T = lambda: def...
9
0
[]
6
sum-of-prefix-scores-of-strings
[Java/Python 3] Trie build/search prefix w/ brief explanation and analysis.
javapython-3-trie-buildsearch-prefix-w-b-ns8l
Build Trie and accumulate the frequencies of each pefix at the same time; then search each word and compute the corresponding score.\n\njava\nclass Trie {\n
rock
NORMAL
2022-09-18T04:20:04.183372+00:00
2022-11-10T12:02:39.116374+00:00
502
false
Build Trie and accumulate the frequencies of each pefix at the same time; then search each word and compute the corresponding score.\n\n```java\nclass Trie {\n int cnt = 0;\n Map<Character, Trie> kids = new HashMap<>();\n public void add(String word) {\n Trie t = this;\n for (char c : word.toChar...
8
0
[]
1
sum-of-prefix-scores-of-strings
✅ One Line Solution
one-line-solution-by-mikposp-ev44
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1 - Brute Force Counting\npython3\nclass
MikPosp
NORMAL
2024-09-25T10:55:20.179735+00:00
2024-09-25T16:43:57.557965+00:00
750
false
(Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)\n\n# Code #1 - Brute Force Counting\n```python3\nclass Solution:\n def sumPrefixScores(self, a: List[str]) -> List[int]:\n return (z:=Counter(s[:i+1] for s in a for i in range(len(s)))) and [sum(z[s[:i...
7
0
['Array', 'String', 'Trie', 'Counting', 'Python', 'Python3']
1
sum-of-prefix-scores-of-strings
String hashing | No trie needed | Python3
string-hashing-no-trie-needed-python3-by-mvdt
Intuition\nWe can use a rolling hash to cumulatively calculate the hash of all the prefixes in O(len(word)).\nThus, we can store the occurences of this hash in
reas0ner
NORMAL
2024-09-25T09:30:05.796482+00:00
2024-09-25T09:30:05.796514+00:00
827
false
# Intuition\nWe can use a rolling hash to cumulatively calculate the hash of all the prefixes in O(len(word)).\nThus, we can store the occurences of this hash in various strings and lookup the counts in a second loop to calculate the score.\n\n# Complexity\n- Time complexity:\nO(len(words) * len(word))\n\n- Space compl...
7
0
['Hash Table', 'Trie', 'Rolling Hash', 'Python3']
3
sum-of-prefix-scores-of-strings
C++ || Trie || Easy to Understand || Visualization
c-trie-easy-to-understand-visualization-pted9
Introduction to Tries\n###### A Trie, also known as a prefix tree, is an efficient tree-like data structure used for storing and searching strings. It\'s partic
khalidalam980
NORMAL
2024-09-25T01:57:33.538219+00:00
2024-09-25T23:46:14.700082+00:00
1,029
false
# Introduction to Tries\n###### A Trie, also known as a prefix tree, is an efficient tree-like data structure used for storing and searching strings. It\'s particularly useful for problems involving prefixes, which makes it ideal for our current challenge.\n\n**In a Trie:**\n- Each node represents a character in a stri...
7
0
['String', 'Trie', 'Counting', 'C++']
2
sum-of-prefix-scores-of-strings
Trie | Java | Beginner friendly🔥
trie-java-beginner-friendly-by-someone_c-i65q
class Solution {\n \n private class TrieNode{\n TrieNode[]children;\n boolean isEnd;\n int pre_count=0;\n \n TrieNode()
someone_codes
NORMAL
2022-09-18T12:06:27.408795+00:00
2022-09-18T13:33:32.097017+00:00
629
false
class Solution {\n \n private class TrieNode{\n TrieNode[]children;\n boolean isEnd;\n int pre_count=0;\n \n TrieNode(){\n children=new TrieNode[26];\n isEnd=false;\n }\n }\n \n private TrieNode root;\n \n private void insert_word(Stri...
7
0
['Trie', 'Java']
0
sum-of-prefix-scores-of-strings
Don't Trie | Simple hashing!
dont-trie-simple-hashing-by-rac101ran-coxd
\nclass Solution {\npublic:\n unordered_map<long long,int> mp;\n long long base = 31 , pw = 1 , mod = 1011001110001111;\n vector<int> sumPrefixScores(v
rac101ran
NORMAL
2022-09-18T04:13:09.000335+00:00
2022-09-18T04:21:40.334824+00:00
1,301
false
```\nclass Solution {\npublic:\n unordered_map<long long,int> mp;\n long long base = 31 , pw = 1 , mod = 1011001110001111;\n vector<int> sumPrefixScores(vector<string>& words) {\n vector<int> ans;\n for(string s : words) {\n long long hash = 0 , pw = 1;\n for(int j=0; j<...
7
0
['C', 'Rolling Hash']
6
sum-of-prefix-scores-of-strings
C++ | Trie | Searching
c-trie-searching-by-surajpatel-5fhj
\nclass Solution {\npublic:\n class Trie {\n public:\n Trie() {\n cnt = 0;\n for(int i=0;i<26;i++){\n this->ne
surajpatel
NORMAL
2022-09-18T04:06:08.934164+00:00
2022-09-18T04:06:08.934204+00:00
770
false
```\nclass Solution {\npublic:\n class Trie {\n public:\n Trie() {\n cnt = 0;\n for(int i=0;i<26;i++){\n this->next[i] = NULL;\n }\n }\n void insert(string word, Trie* root) {\n Trie* node = root;\n int i = 0;\n ...
7
0
['String', 'Trie', 'C']
4
sum-of-prefix-scores-of-strings
TLE Disaster | both hashmap and Trie giving TLE
tle-disaster-both-hashmap-and-trie-givin-w2oo
HashMap\n\nclass Solution {\n public int[] sumPrefixScores(String[] words) {\n \n \n\n int n=words.length;\n int ans[]=new int[n]
deleted_user
NORMAL
2022-09-18T04:01:14.547715+00:00
2022-09-18T04:20:13.883940+00:00
945
false
1. HashMap\n```\nclass Solution {\n public int[] sumPrefixScores(String[] words) {\n \n \n\n int n=words.length;\n int ans[]=new int[n];\n \n HashMap<String,Integer> map=new HashMap<>();\n HashMap<Integer,HashSet<String>> sub_str=new HashMap<>();\n for(int i=0;...
7
2
['Trie']
2
sum-of-prefix-scores-of-strings
String Hashing || Java
string-hashing-java-by-virendra115-hla6
\npublic int[] sumPrefixScores(String[] words) {\n int n = words.length, p = 31, m = (int)1e9 + 9;\n int[] ans = new int[n];\n long[] hash = new long[n
virendra115
NORMAL
2022-09-18T04:11:45.663418+00:00
2022-09-18T04:23:51.725873+00:00
734
false
```\npublic int[] sumPrefixScores(String[] words) {\n int n = words.length, p = 31, m = (int)1e9 + 9;\n int[] ans = new int[n];\n long[] hash = new long[n], p_pow = new long[n];\n Arrays.fill(p_pow,1);\n for(int i = 0; i < 1000; i++){\n Map<Long,Integer> map = new HashMap<>();\n for(int j =...
6
1
[]
3
sum-of-prefix-scores-of-strings
Optimized Solution Using a Custom Trie for Prefix Scores | Java | C++ | [Video Explanation]
optimized-solution-using-a-custom-trie-f-djsu
Intuition, approach, and complexity discussed in detail in the video solution\nhttps://youtu.be/HymJeL_ERlg\n# Code\njava []\nclass TrieNode{\n TrieNode chil
Lazy_Potato_
NORMAL
2024-09-25T11:30:53.165075+00:00
2024-09-25T11:30:53.165120+00:00
471
false
# Intuition, approach, and complexity discussed in detail in the video solution\nhttps://youtu.be/HymJeL_ERlg\n# Code\n``` java []\nclass TrieNode{\n TrieNode children[] = new TrieNode[26];\n int nodeFreq = 0;\n void insert(String key){\n TrieNode curr = this;\n for(var chr : key.toCharArray()){\...
5
0
['Array', 'String', 'Trie', 'Counting', 'C++', 'Java']
1
sum-of-prefix-scores-of-strings
🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏
beats-super-easy-beginners-by-codewithsp-j2vs
\n\n\n---\n\n## Intuition\nThe task involves calculating the "prefix score" for each word in a list, where the prefix score is the sum of the counts of all pref
CodeWithSparsh
NORMAL
2024-09-25T05:51:19.848217+00:00
2024-09-25T05:51:19.848287+00:00
517
false
![image.png](https://assets.leetcode.com/users/images/efd10c26-468e-41a6-8e7b-2772a09c8cea_1727243131.880963.png)\n\n\n---\n\n## Intuition\nThe task involves calculating the "prefix score" for each word in a list, where the prefix score is the sum of the counts of all prefixes of the word in the given word list. The Tr...
5
0
['Trie', 'C', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'Dart']
0
sum-of-prefix-scores-of-strings
💡 O(n⋅m) | Easy Solution | C++ 462ms Beats 87.78% | Java Py3
onm-easy-solution-c-462ms-beats-8778-jav-xvcp
\n#\n---\n\n# Intuition\nWe can efficiently solve this problem using a Trie (prefix tree). A Trie helps in storing prefixes and counting their occurrences while
user4612MW
NORMAL
2024-09-25T03:02:45.557215+00:00
2024-09-25T03:08:23.334455+00:00
579
false
\n#\n---\n\n# **Intuition**\nWe can efficiently solve this problem using a **Trie** (prefix tree). A **Trie** helps in storing prefixes and counting their occurrences while reducing redundant comparisons. Each node in the Trie represents a character, and we increment the count for each character as we insert the string...
5
0
['Trie', 'C++', 'Java', 'Python3']
2
sum-of-prefix-scores-of-strings
🌟 Multi-Language Solution for Prefix Score Mastery Made Easy 🔥💯
multi-language-solution-for-prefix-score-xokw
\n\nExplore a collection of solutions to LeetCode problems in multiple programming languages. Each solution includes a detailed explanation and step-by-step app
withaarzoo
NORMAL
2024-09-25T02:00:06.001079+00:00
2024-09-25T02:00:06.001099+00:00
1,126
false
![Screenshot 2024-07-02 113653.png](https://assets.leetcode.com/users/images/22b27ce5-85a0-45cc-89aa-31733bd82399_1727228994.2532544.png)\n\nExplore a collection of solutions to LeetCode problems in multiple programming languages. Each solution includes a detailed explanation and step-by-step approach to solving the pr...
5
0
['Array', 'String', 'Trie', 'Counting', 'Python', 'C++', 'Java', 'Go', 'Python3', 'JavaScript']
2
sum-of-prefix-scores-of-strings
💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100
easiestfaster-lesser-cpython3javacpython-vnqu
Intuition\n\n Describe your first thoughts on how to solve this problem. \n- JavaScript Code --> https://leetcode.com/problems/sum-of-prefix-scores-of-strings/s
Edwards310
NORMAL
2024-09-25T01:10:19.347447+00:00
2024-09-25T01:10:19.347482+00:00
546
false
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/91aaf15e-0d29-4037-b6d4-001a79697047_1727226424.1205616.jpeg)\n<!-- Describe your first thoughts on how to solve this problem. -->\n- ***JavaScript Code -->*** https://leetcode.com/problems/sum-of-prefix-scores-of-strings/submissions/1401331474?...
5
0
['Array', 'String', 'Trie', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#']
0
sum-of-prefix-scores-of-strings
Hashing C++ easy to understand
hashing-c-easy-to-understand-by-virujtha-fu19
The hashing technique is simple. The algorithm states that\n1) Assign a hash code to all prefixes of a word ( Using any hash function or Rabin Karp algorithm).
virujthakur01
NORMAL
2022-10-04T08:50:33.236092+00:00
2022-10-04T08:50:33.236138+00:00
702
false
The hashing technique is simple. The algorithm states that\n1) Assign a hash code to all prefixes of a word ( Using any hash function or Rabin Karp algorithm). Repeat this for every word in the list of words.\n2) Alongside maintain a frequency map for the hash code, or the prefix, which maintains the number of occurren...
5
0
['C']
1
sum-of-prefix-scores-of-strings
C++ Simple DP solution without Trie (Beats 99% runtime, 97% Space)
c-simple-dp-solution-without-trie-beats-ov5kw
Firstly Sort the array of strings without losing original indices (eg: by using vector>).\n\nThis solution takes advantage of the fact that after sorting the st
Sadid_005
NORMAL
2022-09-21T15:44:40.241986+00:00
2022-09-21T17:50:02.069792+00:00
365
false
Firstly Sort the array of strings without losing original indices (eg: by using vector<pair<string,int>>).\n\nThis solution takes advantage of the fact that after sorting the strings with identical prefixes will form a consecutive segment.\n\nExample: \nBefore Sorting => "abc" "bc" "ab" "b"\nAfter Sorting => *...
5
0
['Dynamic Programming', 'Sorting']
0
sum-of-prefix-scores-of-strings
Concise Python Tire Implementation
concise-python-tire-implementation-by-51-0hcb
\nclass TrieNode:\n def __init__(self):\n self.next = {}\n self.score = 0\n\n\nclass Solution:\n def sumPrefixScores(self, words: List[str])
515384231
NORMAL
2022-09-18T04:32:32.377861+00:00
2022-09-18T04:32:32.377892+00:00
292
false
```\nclass TrieNode:\n def __init__(self):\n self.next = {}\n self.score = 0\n\n\nclass Solution:\n def sumPrefixScores(self, words: List[str]) -> List[int]:\n result = []\n \n root = TrieNode()\n \n # build the trie\n for i, word in enumerate(words):\n ...
5
0
['Trie', 'Python']
3
sum-of-prefix-scores-of-strings
C++ Explained Solution | Using Trie | Time - O(NM) |
c-explained-solution-using-trie-time-onm-24d5
Approach -\nStep 1 - Create a node class that stores characters, a pointer to its next characters \nand count how many times this character appears in every pre
abhinandan__22
NORMAL
2022-09-18T04:00:41.335302+00:00
2022-09-18T04:13:00.278526+00:00
222
false
**Approach -**\n**Step 1** - Create a node class that stores characters, a pointer to its next characters \nand count how many times this character appears in every prefix of every string of a given vector\n**Step 2** - Create a trie class that has to member function\ni) Push - To push the string in trie\nii) Score - T...
5
0
[]
0
sum-of-prefix-scores-of-strings
Dcc 25/09/2024 || Trie 🔥
dcc-25092024-trie-by-sajaltiwari007-tn1u
Intuition:\nThe problem involves calculating the sum of prefix scores for each word in an array of words. The prefix score of a word is determined by the number
sajaltiwari007
NORMAL
2024-09-25T09:24:24.553515+00:00
2024-09-25T09:24:24.553554+00:00
100
false
### Intuition:\nThe problem involves calculating the sum of prefix scores for each word in an array of words. The prefix score of a word is determined by the number of times its prefixes appear across all the words in the list.\n\nA **Trie** (prefix tree) is well-suited for problems involving prefixes because it allows...
4
0
['Trie', 'Java']
0