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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
vowels-of-all-substrings | [Java] Simple Solution with Approach | java-simple-solution-with-approach-by-sv-hzoe | Consider an string - axexixoxu\n\n\n\n\n\n\nclass Solution {\n public long countVowels(String word) {\n \n char[] arr = word.toCharArray();\n | svmgarg | NORMAL | 2021-12-31T06:48:06.953431+00:00 | 2021-12-31T06:49:16.983483+00:00 | 109 | false | Consider an string - axexixoxu\n\n\n\n\n```\n\nclass Solution {\n public long countVowels(String word) {\n \n char[] arr = word.toCharArray();\n int n = arr.length;\n \n lo... | 1 | 0 | [] | 1 |
vowels-of-all-substrings | C++ easy solution using maths | c-easy-solution-using-maths-by-hunny123-ojd9 | class Solution {\npublic:\n long long countVowels(string s) {\n long long res=0;\n for(int i=0;i<s.length();i++)\n\n {\n if(s | hunny123 | NORMAL | 2021-12-26T17:28:05.911423+00:00 | 2021-12-26T17:28:05.911472+00:00 | 96 | false | class Solution {\npublic:\n long long countVowels(string s) {\n long long res=0;\n for(int i=0;i<s.length();i++)\n\n {\n if(s[i]==\'a\'||s[i]==\'e\'||s[i]==\'o\'||s[i]==\'u\'||s[i]==\'i\')\n {\n res=res+(s.length()-i)*(i+1);\n }\n \n... | 1 | 0 | [] | 0 |
vowels-of-all-substrings | Faster || C++ || O(N) || Using map only | faster-c-on-using-map-only-by-shubhamp07-cyfp | ```\nclass Solution {\npublic:\n long long countVowels(string word) {\n \n long long int ans = 0; //This will be the final answer\n \n | shubhamp07 | NORMAL | 2021-11-21T09:24:14.954299+00:00 | 2021-11-21T09:24:34.762568+00:00 | 134 | false | ```\nclass Solution {\npublic:\n long long countVowels(string word) {\n \n long long int ans = 0; //This will be the final answer\n \n unordered_map<char , int > mp; // Unordered map of char to int\n \n mp[\'a\']=1; mp[\'e\']=1; mp[\'i\']=1; mp[\'o\']=1; mp[\'u\']=1;\n ... | 1 | 0 | [] | 0 |
vowels-of-all-substrings | C++ Easy Solution | c-easy-solution-by-urveshgodhani-6esf | \t\tlong long count = 0;\n long long ans = 0;\n \n for(int i = 0 ; i < word.size() ; i++)\n {\n if(word[i] == \'a\' || wo | urveshgodhani | NORMAL | 2021-11-16T04:53:29.807005+00:00 | 2021-11-16T04:53:29.807053+00:00 | 153 | false | \t\tlong long count = 0;\n long long ans = 0;\n \n for(int i = 0 ; i < word.size() ; i++)\n {\n if(word[i] == \'a\' || word[i] == \'e\' || word[i] == \'i\' || word[i] == \'o\' || word[i] == \'u\')\n count += (i+1);\n \n ans += count;\n }\n ... | 1 | 0 | ['C', 'C++'] | 0 |
vowels-of-all-substrings | C++ o(n) simple solution using concept of Arithmetic Progression | c-on-simple-solution-using-concept-of-ar-5mcj | \tclass Solution {\n\tpublic:\n\t\tlong long a, res;\n\t\tlong long count(long long &a, long long &n){\n\t\t\treturn (n(2a+(n-1)*-2))/2;\n\t\t}\n\t\tlong long c | gauravchaurasia1704 | NORMAL | 2021-11-15T14:00:27.492032+00:00 | 2021-11-15T14:00:27.492059+00:00 | 102 | false | \tclass Solution {\n\tpublic:\n\t\tlong long a, res;\n\t\tlong long count(long long &a, long long &n){\n\t\t\treturn (n*(2*a+(n-1)*-2))/2;\n\t\t}\n\t\tlong long countVowels(string &word) {\n\t\t\tres = 0;\n\t\t\ta=word.size();\n\t\t\tfor(long long i=1; i<=word.size(); i++){\n\t\t\t\tif(word[i-1] == \'a\' || word[i-1] =... | 1 | 1 | [] | 0 |
vowels-of-all-substrings | Java O(N) Solution with 1-D dp | java-on-solution-with-1-d-dp-by-joejoe33-i8zo | \nclass Solution {\n private boolean isVowelChar(char c) {\n return c==\'a\' || c==\'e\' || c==\'i\' || c==\'o\' || c==\'u\';\n }\n public long | joejoe3333 | NORMAL | 2021-11-13T21:42:11.133384+00:00 | 2021-11-13T21:42:11.133426+00:00 | 122 | false | ```\nclass Solution {\n private boolean isVowelChar(char c) {\n return c==\'a\' || c==\'e\' || c==\'i\' || c==\'o\' || c==\'u\';\n }\n public long countVowels(String word) {\n if (word == null || word.length() == 0) {\n return 0L;\n }\n // create 1 dp array\n long[... | 1 | 0 | [] | 0 |
vowels-of-all-substrings | C++|| Observation Based Solution||TC: O(n) and SC: O(1) | c-observation-based-solutiontc-on-and-sc-gw35 | ```\nclass Solution {\npublic:\n long long countVowels(string word) {\n \n long long ans =0;\n int n =word.size();\n for(int i=0;i<n | Kishan_Srivastava | NORMAL | 2021-11-09T13:13:52.038049+00:00 | 2021-11-09T13:13:52.038093+00:00 | 58 | false | ```\nclass Solution {\npublic:\n long long countVowels(string word) {\n \n long long ans =0;\n int n =word.size();\n for(int i=0;i<n;i+=1)\n { \n // if ith index has vowel\n // then that vowel is in (i+1)*(n-i) substrings\n if(word[i]==\'a\' or word[... | 1 | 0 | [] | 1 |
vowels-of-all-substrings | Golang very simple O(n) solution | golang-very-simple-on-solution-by-tjucod-9heo | go\nfunc countVowels(word string) int64 {\n vowel := int64(0)\n magic := int64(0)\n for i, v := range word {\n switch v {\n case \'a\', \ | tjucoder | NORMAL | 2021-11-08T15:30:43.195961+00:00 | 2021-11-08T15:30:43.195995+00:00 | 75 | false | ```go\nfunc countVowels(word string) int64 {\n vowel := int64(0)\n magic := int64(0)\n for i, v := range word {\n switch v {\n case \'a\', \'e\', \'i\', \'o\', \'u\':\n magic += int64(i) + 1\n }\n vowel += magic\n }\n return vowel\n}\n``` | 1 | 0 | ['Go'] | 0 |
vowels-of-all-substrings | C# Clear Solution with Explanation | c-clear-solution-with-explanation-by-aip-nvie | My way to come up with the formula:\n\nWord: abcdef\n\nPossible substrings:\na ab abc abcd abcde abcdef\nb bc bcd bcde bcdef\nc cd cde cdef\nd de def\ne ef\nf\n | AIP | NORMAL | 2021-11-08T13:32:32.021920+00:00 | 2021-11-08T13:35:24.428045+00:00 | 90 | false | **My way to come up with the formula:**\n```\nWord: abcdef\n\nPossible substrings:\na ab abc abcd abcde abcdef\nb bc bcd bcde bcdef\nc cd cde cdef\nd de def\ne ef\nf\n\nWordLength = 6\nword[0] a: 6 (6 substrings in a first row)\nword[1] b: 5 + 5 (5 substrings in a first row and 5 substrings in a second row)\nword[2] c:... | 1 | 0 | [] | 0 |
vowels-of-all-substrings | O(n) time, O(1) solution [C++] | on-time-o1-solution-c-by-mandysingh150-t75b | Faster than 100%, O(n) time, O(1) space\n\nEvery vowel character will occur in (i+1) * (size-i) substrings, where i is the index of the vowel character in strin | mandysingh150 | NORMAL | 2021-11-08T06:31:56.161543+00:00 | 2021-11-08T06:34:11.159075+00:00 | 32 | false | **Faster than 100%, O(n) time, O(1) space**\n\nEvery vowel character will occur in **(i+1) * (size-i)** substrings, where **i** is the index of the vowel character in string.\n```\nclass Solution {\npublic:\n bool isVowel(char ch) {\n return ch==\'a\' or ch==\'e\' or ch==\'i\' or ch==\'o\' or ch==\'u\';\n ... | 1 | 0 | [] | 0 |
vowels-of-all-substrings | 2063. Vowels of All Substrings||C++||with Explanation | 2063-vowels-of-all-substringscwith-expla-jg8z | Logic-\nWeight that char (at index i), Ci is contributing is given by, \n= Number of substrings containing that index char (if Ci is vowel)\n =0 (otherwise if | guptasim8 | NORMAL | 2021-11-08T06:02:50.083668+00:00 | 2021-11-08T06:02:50.083703+00:00 | 179 | false | Logic-\nWeight that char (at index i), Ci is contributing is given by, \n= Number of substrings containing that index char (if Ci is vowel)\n =0 (otherwise if char Ci is not a vowel)\n \nThe total sum of the number of vowels (\'a\', \'e\', \'i\', \'o\', and \'u\') in every substring of word will be equal to the sum of... | 1 | 0 | ['C', 'C++'] | 0 |
vowels-of-all-substrings | (C++) 2063. Vowels of All Substrings | c-2063-vowels-of-all-substrings-by-qeetc-764q | \n\nclass Solution {\npublic:\n long long countVowels(string word) {\n long ans = 0; \n string vowel = "aeiou"; \n for (long i = 0; i < | qeetcode | NORMAL | 2021-11-07T21:51:43.516561+00:00 | 2021-11-07T21:51:43.516590+00:00 | 45 | false | \n```\nclass Solution {\npublic:\n long long countVowels(string word) {\n long ans = 0; \n string vowel = "aeiou"; \n for (long i = 0; i < word.size(); ++i) \n if (vowel.find(word[i]) != string::npos)\n ans += (i+1)*(word.size()-i); \n return ans; \n }\n};\n``... | 1 | 0 | ['C'] | 0 |
vowels-of-all-substrings | Javascript easy solution. O(n) | javascript-easy-solution-on-by-jupiterjw-qapz | \n// Save vowels in a set\nconst VOWELS = new Set([\'a\', \'e\', \'i\', \'o\', \'u\']);\n\n/**\n * @param {string} word\n * @return {number}\n */\nconst countVo | JupiterJW | NORMAL | 2021-11-07T19:59:30.151060+00:00 | 2021-11-07T20:03:41.315804+00:00 | 149 | false | ```\n// Save vowels in a set\nconst VOWELS = new Set([\'a\', \'e\', \'i\', \'o\', \'u\']);\n\n/**\n * @param {string} word\n * @return {number}\n */\nconst countVowels = function(word) {\n let count = 0;\n\n const length = word.length;\n // Return diretly if the word is empty\n if (!length) {\n return count;\n... | 1 | 0 | ['JavaScript'] | 0 |
vowels-of-all-substrings | ✔Simple and Short || C++ Approach | simple-and-short-c-approach-by-sarvesh_2-9k10 | bool check(char x){\n \n \n if(x==\'a\' || x==\'e\' || x==\'i\' || x==\'o\' || x==\'u\') return true;\n else return false;\n }\n | sarvesh_2-1 | NORMAL | 2021-11-07T19:48:18.843448+00:00 | 2021-11-07T19:48:18.843530+00:00 | 57 | false | bool check(char x){\n \n \n if(x==\'a\' || x==\'e\' || x==\'i\' || x==\'o\' || x==\'u\') return true;\n else return false;\n }\n long long countVowels(string word) {\n \n long long ans=0;\n \n \n for(int i=0;i<word.size();i++)\n {\n ... | 1 | 0 | ['C', 'C++'] | 0 |
vowels-of-all-substrings | C++||Very Short Solution|| One optimized solution but still TLE|| | cvery-short-solution-one-optimized-solut-ppkf | \t//Use of Little Math\n\tclass Solution {\n\tpublic:\n long long countVowels(string word) {\n double count=0;\n double n=word.size();\n | kundankumar4348 | NORMAL | 2021-11-07T16:13:34.856314+00:00 | 2021-11-07T16:13:34.856361+00:00 | 44 | false | \t//Use of Little Math\n\tclass Solution {\n\tpublic:\n long long countVowels(string word) {\n double count=0;\n double n=word.size();\n for(double i=0;i<n;++i){\n if(word[i]==\'a\' || word[i]==\'e\'||word[i]==\'i\'||word[i]==\'o\'||word[i]==\'u\')\n count+=((i+1)*(n-i)... | 1 | 0 | [] | 1 |
vowels-of-all-substrings | [Python 3] two prefix sums | python-3-two-prefix-sums-by-chestnut8901-4hrn | ```\nclass Solution:\n def countVowels(self, word: str) -> int:\n n = len(word)\n \n # mark vowel\n # \'aba\' vowels = [1, 0, 1]\ | chestnut890123 | NORMAL | 2021-11-07T16:06:21.690376+00:00 | 2021-11-07T16:06:21.690410+00:00 | 121 | false | ```\nclass Solution:\n def countVowels(self, word: str) -> int:\n n = len(word)\n \n # mark vowel\n # \'aba\' vowels = [1, 0, 1]\n vowels = list(map(lambda x: int(x in \'aeiou\'), word))\n \n # add vowel count in each substring\n # acc = [0, 1, 1, 2]\n a... | 1 | 0 | ['Prefix Sum', 'Python', 'Python3'] | 0 |
vowels-of-all-substrings | easy solution using (size -i)*(i+1) || C++ | easy-solution-using-size-ii1-c-by-gravit-982e | \nclass Solution {\npublic:\n long long countVowels(string s) {\n long long n = s.length();\n long long sum = 0;\n for (long long i = 0; | gravity2000 | NORMAL | 2021-11-07T07:49:41.672225+00:00 | 2021-11-07T07:49:41.672256+00:00 | 57 | false | ```\nclass Solution {\npublic:\n long long countVowels(string s) {\n long long n = s.length();\n long long sum = 0;\n for (long long i = 0; i < n; i++)\n if (s[i] == \'a\' || s[i] == \'e\' || s[i] == \'i\' || s[i] == \'o\' || s[i] == \'u\')\n sum += (n-i)*(i+1);\n ... | 1 | 1 | ['C'] | 0 |
vowels-of-all-substrings | [Java] Easy Solution O(n) with Explanation | java-easy-solution-on-with-explanation-b-xa80 | To find number of substrings which have a vowel at index i:\n\n\t\t\tsubstrings ending with index i: i\n\t\t\tsubstrings starting with index i | ippilimahesh1999 | NORMAL | 2021-11-07T06:49:16.506415+00:00 | 2021-11-07T06:49:16.506460+00:00 | 158 | false | To find number of substrings which have a vowel at index i:\n\n\t\t\tsubstrings ending with index i: i\n\t\t\tsubstrings starting with index i: n - i\n\t\t\tsubstrings contains index i in the middle: i * (n - i - 1) \n\t\t\t\n\t\t\tSo total will be addition of all : i + (n-i) + (i*(n-... | 1 | 0 | ['Java'] | 1 |
vowels-of-all-substrings | Simple java single pass DP O(n) | simple-java-single-pass-dp-on-by-seqquoi-ixvn | \n\n\npublic long countVowels(String word) {\n long cnt = 0;\n int n = word.length();\n long dp[] = new long[n+1];\n Set<Character> | seqquoia | NORMAL | 2021-11-07T06:48:01.714832+00:00 | 2021-11-07T06:48:01.714873+00:00 | 242 | false | \n\n```\npublic long countVowels(String word) {\n long cnt = 0;\n int n = word.length();\n long dp[] = new long[n+1];\n Set<Character> vowels = new HashSet<Character>();\n vowels.add(\'a\');vowels.add(\'e\');vowels.add(\'i\');vowels.add(\'o\');vowels.add(\'u\'); \n \n fo... | 1 | 1 | ['String', 'Dynamic Programming', 'Java'] | 0 |
vowels-of-all-substrings | Can anyone explain my approach:)..Easy O(n) simplest solution.(Python) | can-anyone-explain-my-approacheasy-on-si-zkc1 | \n\t\n c=0\n ans=0\n for i in range(len(word)):\n if word[i] in [\'a\',\'e\',\'i\',\'o\',\'u\']:\n c+=1 # fo | athulzkrish | NORMAL | 2021-11-07T04:49:51.227539+00:00 | 2021-11-07T04:49:51.227582+00:00 | 90 | false | \n\t\n c=0\n ans=0\n for i in range(len(word)):\n if word[i] in [\'a\',\'e\',\'i\',\'o\',\'u\']:\n c+=1 # for all substrings from this point, vowels accumulated\n c+=i # for all substrings till this point, the count of vowel is accumulated\n ... | 1 | 0 | ['Python'] | 1 |
vowels-of-all-substrings | [Python3] greedy 1-line O(N) | python3-greedy-1-line-on-by-ye15-qwaw | Please check out this commit for solutions of weekly 266. \n\n\nclass Solution:\n def countVowels(self, word: str) -> int:\n return sum((i+1)*(len(wor | ye15 | NORMAL | 2021-11-07T04:23:03.580501+00:00 | 2021-11-07T05:11:30.898902+00:00 | 124 | false | Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/6b6e6b9115d2b659e68dcf3ea8e21befefaae16c) for solutions of weekly 266. \n\n```\nclass Solution:\n def countVowels(self, word: str) -> int:\n return sum((i+1)*(len(word)-i) for i, x in enumerate(word) if x in "aeiou")\n``` | 1 | 1 | ['Python3'] | 0 |
vowels-of-all-substrings | C++|| O(n) || explained | c-on-explained-by-ygehi9527-8ll5 | Idea: The idea is to use a prefix sum array-based technique where we store the occurrences of each character in all the substrings concatenated. \n\nclass Solut | ygehi9527 | NORMAL | 2021-11-07T04:08:13.423753+00:00 | 2021-11-07T07:02:39.616053+00:00 | 127 | false | Idea: The idea is to use a prefix sum array-based technique where we store the occurrences of each character in all the substrings concatenated. \n```\nclass Solution {\npublic:\n long long countVowels(string s) {\n long long n = s.length();\n vector<long long> v;\n\n for (long long i = 0; i < n... | 1 | 0 | ['C', 'C++'] | 1 |
maximum-compatibility-score-sum | Backtracking with STL | 10 lines of code | C++ | backtracking-with-stl-10-lines-of-code-c-7n5v | As constraints 1 <= m, n <= 8 are very small, we can easily get our answer by evaluating all possible combinations. \nTo generate all possible combinations of | av1shek | NORMAL | 2021-07-25T04:06:37.883365+00:00 | 2021-07-25T04:06:37.883409+00:00 | 7,114 | false | As constraints ```1 <= m, n <= 8``` are very small, we can easily get our answer by evaluating all possible combinations. \nTo generate all possible combinations of students and mentors, we can shuffle any one of them in all possible way.\n\nIn below code i m trying to shuffle students, but shuffling of vector can be ... | 86 | 6 | [] | 19 |
maximum-compatibility-score-sum | [Java] || Backtracking || Easy to Understand | java-backtracking-easy-to-understand-by-li3qd | \t\n\tclass Solution {\n\t\tint max;\n\t\tpublic int maxCompatibilitySum(int[][] students, int[][] mentors) {\n\t\t\tboolean[] visited = new boolean[students.le | Vishnu_Jupiter | NORMAL | 2021-07-25T04:12:41.257837+00:00 | 2021-11-18T12:24:46.502030+00:00 | 5,081 | false | \t\n\tclass Solution {\n\t\tint max;\n\t\tpublic int maxCompatibilitySum(int[][] students, int[][] mentors) {\n\t\t\tboolean[] visited = new boolean[students.length];\n\t\t\thelper(visited, students, mentors, 0, 0);\n\t\t\treturn max;\n\t\t}\n\t\tpublic void helper(boolean[] visited, int[][] students, int[][] mentors, ... | 67 | 2 | ['Backtracking', 'Java'] | 17 |
maximum-compatibility-score-sum | [C++] DP + Bitmask | 4ms | c-dp-bitmask-4ms-by-divyanshu1-mf7l | Time Complexity: O((2^n)*n*m)\n\n\n\nint dp[300]; //dp-array\nclass Solution {\npublic:\n int solve(vector<int> &a, vector<int> &b, int i, int mask, int | divyanshu1 | NORMAL | 2021-07-25T04:01:19.793394+00:00 | 2021-09-22T00:06:03.172079+00:00 | 5,719 | false | Time Complexity: `O((2^n)*n*m)`\n\n```\n\nint dp[300]; //dp-array\nclass Solution {\npublic:\n int solve(vector<int> &a, vector<int> &b, int i, int mask, int n, int m){\n if(i>=n){\n return 0;\n }\n if(dp[mask]!=-1){\n return dp[mask];\n }\n int ans=0;\n ... | 60 | 8 | [] | 6 |
maximum-compatibility-score-sum | C++ Brute force DFS | c-brute-force-dfs-by-lzl124631x-sgow | See my latest update in repo LeetCode\n\n## Solution 1. Brute Force (DFS)\n\nThe brute force solution is generating all the permuntations of the mentors and cal | lzl124631x | NORMAL | 2021-07-25T04:01:50.614797+00:00 | 2021-07-25T04:13:07.988131+00:00 | 3,137 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Brute Force (DFS)\n\nThe brute force solution is generating all the permuntations of the mentors and calculate the score of this permutation and the students.\n\nThe permutation generation process with DFS takes `O(M! * M)... | 32 | 5 | [] | 7 |
maximum-compatibility-score-sum | [C++] Backtracking Solution | c-backtracking-solution-by-manishbishnoi-kzxm | \nclass Solution {\n // Calculating compatibility scores of ith student and jth mentor\n int cal(int i,int j,vector<vector<int>>& arr1,vector<vector<int>> | manishbishnoi897 | NORMAL | 2021-07-25T04:03:33.466450+00:00 | 2021-07-25T04:05:58.542661+00:00 | 2,219 | false | ```\nclass Solution {\n // Calculating compatibility scores of ith student and jth mentor\n int cal(int i,int j,vector<vector<int>>& arr1,vector<vector<int>>& arr2){\n int cnt=0;\n for(int k=0;k<arr1[0].size();k++){\n if(arr1[i][k]==arr2[j][k]){\n cnt++;\n }\n ... | 26 | 3 | ['Backtracking', 'C'] | 2 |
maximum-compatibility-score-sum | [Python3] permutations | python3-permutations-by-ye15-ucw2 | Approach 1 - brute force\n\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n m = len(stu | ye15 | NORMAL | 2021-07-25T04:01:47.612282+00:00 | 2021-07-26T18:12:14.887824+00:00 | 2,339 | false | **Approach 1 - brute force**\n```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n m = len(students)\n \n score = [[0]*m for _ in range(m)]\n for i in range(m): \n for j in range(m): \n score[i][j] = ... | 26 | 4 | ['Python3'] | 3 |
maximum-compatibility-score-sum | Mask DP | mask-dp-by-votrubac-jj2s | With m and n constrained to 8, it\'s feasible to just check all permutations.\n \nWe just check all possible assignments for each student i, using mask to track | votrubac | NORMAL | 2021-07-25T04:01:14.536236+00:00 | 2021-07-25T05:51:32.976298+00:00 | 3,345 | false | With `m` and `n` constrained to `8`, it\'s feasible to just check all permutations.\n \nWe just check all possible assignments for each student `i`, using `mask` to track mentors that have been assigned. We track and return the maximum score.\n \nTo speed things up, we can use memoisation, where we store interim result... | 21 | 2 | [] | 10 |
maximum-compatibility-score-sum | [Javascript] Optimal Hungarian Algorithm in O(m*m*n) | javascript-optimal-hungarian-algorithm-i-l0db | Intuition:\n\nThis may strike one as a bipartite graph problem, where the nodes of the left part are the students and the nodes of the right part are the mentor | George_Chrysochoou | NORMAL | 2021-07-25T09:49:23.618006+00:00 | 2021-07-25T09:50:07.172193+00:00 | 1,542 | false | **Intuition**:\n\nThis may strike one as a bipartite graph problem, where the nodes of the left part are the students and the nodes of the right part are the mentors. Each node on the left is connected with every node on the right, with a cost equal to the count of the same answers for the student and each mentor respe... | 13 | 0 | ['Graph', 'JavaScript'] | 3 |
maximum-compatibility-score-sum | Classical Dijkstra in Python with clear explanation (Similar with 1066) | classical-dijkstra-in-python-with-clear-0yqmx | This questions is similar to 1066. Campus Bike II. Please also refer to my post: Classical Dijkstra in Python with clear explanation\n\nWorkers -> Students, Bik | Lunius | NORMAL | 2021-07-25T04:09:24.737016+00:00 | 2021-07-28T00:43:12.191419+00:00 | 936 | false | This questions is similar to [1066. Campus Bike II](https://leetcode.com/problems/campus-bikes-ii/). Please also refer to my post: [Classical Dijkstra in Python with clear explanation](https://leetcode.com/problems/campus-bikes-ii/discuss/478958/classical-dijkstra-in-python-with-clear-explanation)\n\n`Workers` -> `Stud... | 11 | 0 | ['Python'] | 2 |
maximum-compatibility-score-sum | (JAVA)DP + Bitmasking | 2ms | javadp-bitmasking-2ms-by-ashuman231-6l8w | \nTimeComplexity : (m * 2 ^ m) * n\nSpace Complexity: m * (2 ^ m)\n\n```\nclass Solution {\n\n\tstatic int dp[][] = null;\n\tstatic int all_visited = 0;\n\tint | ashuman231 | NORMAL | 2021-07-25T04:04:38.608668+00:00 | 2021-07-25T07:54:22.116923+00:00 | 1,028 | false | \nTimeComplexity : (m * 2 ^ m) * n\nSpace Complexity: m * (2 ^ m)\n\n```\nclass Solution {\n\n\tstatic int dp[][] = null;\n\tstatic int all_visited = 0;\n\tint fun(int pos, int mask, int[][] students, int[][] mentors, int m, int n) {\n\n\n\t\tif (mask == all_visited) {\n\t\t\tdp[pos][mask] = 0;\n\t\t\treturn 0;\n\t\t}\... | 11 | 3 | [] | 0 |
maximum-compatibility-score-sum | [C++] OPTIMIZED Backtracking solution; Include Complexity Analysis; Beats 100% | c-optimized-backtracking-solution-includ-r5uo | \nint res;\n\nvoid backtracking(vector<vector<int>> &vec, int pos, vector<int> &visited, int count) {\n\tif (pos == vec.size()) {\n\t\tres = max(res, count);\n\ | brandonbai | NORMAL | 2021-07-25T04:02:28.858386+00:00 | 2021-07-25T04:55:05.313583+00:00 | 694 | false | ```\nint res;\n\nvoid backtracking(vector<vector<int>> &vec, int pos, vector<int> &visited, int count) {\n\tif (pos == vec.size()) {\n\t\tres = max(res, count);\n\t\treturn;\n\t}\n\tfor (int i = 0; i < vec.size() ; i++) {\n\t\tif (visited[i] == 1)\n\t\t\tcontinue;\n\t\tvisited[i] = 1;\n\t\tbacktracking(vec, pos + 1, vi... | 10 | 2 | [] | 5 |
maximum-compatibility-score-sum | dp+bitmask => 100%fast c++ | dpbitmask-100fast-c-by-__hokaage-ub1a | \tclass Solution {\n\tpublic:\n\t\tint dp[15][5000],m;\n \n int sol(vector&stud,vector&ment,int i,int mask){\n //cout<<"here\n";\n if(i>=siz | __hokaage__ | NORMAL | 2021-07-25T04:24:05.505977+00:00 | 2021-07-25T04:26:33.886917+00:00 | 589 | false | \tclass Solution {\n\tpublic:\n\t\tint dp[15][5000],m;\n \n int sol(vector<int>&stud,vector<int>&ment,int i,int mask){\n //cout<<"here\\n";\n if(i>=size(stud))\n return 0;\n \n if(dp[i][mask]!=-1)\n return dp[i][mask];\n \n int ans=0,score;\n ... | 9 | 3 | [] | 5 |
maximum-compatibility-score-sum | Python Backtracking | python-backtracking-by-theonepieceisreal-32hu | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n n = len(students)\n \n | theonepieceisreal | NORMAL | 2021-07-25T04:11:48.047753+00:00 | 2021-07-25T04:11:48.047779+00:00 | 753 | false | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n n = len(students)\n \n def dfs(i, used, score):\n if i == n: return score\n \n res = float(-inf)\n \n for j, mentor in enumer... | 9 | 0 | [] | 2 |
maximum-compatibility-score-sum | Python3. Straightforward top down dp | python3-straightforward-top-down-dp-by-y-jj2c | \nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n pair_score = defaultdict(int)\n | yaroslav-repeta | NORMAL | 2021-07-25T04:03:49.109818+00:00 | 2021-07-25T04:03:49.109862+00:00 | 763 | false | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n pair_score = defaultdict(int)\n n = len(students)\n\n # build compatibilty score for every possible student-mentor pair\n for i in range(n):\n for j in range(n):\... | 9 | 1 | [] | 1 |
maximum-compatibility-score-sum | C++ | DP | BITMASKING | Beats 95% | c-dp-bitmasking-beats-95-by-wayward_blue-88bt | \nclass Solution {\npublic:\n int dp[8][1<<8];\n int ans = 0;\n int dfs(vector<vector<int>>& students, vector<vector<int>>&mentors, int idx, int mask){ | wayward_blue | NORMAL | 2022-03-10T11:33:49.496174+00:00 | 2022-03-10T11:33:49.496211+00:00 | 344 | false | ```\nclass Solution {\npublic:\n int dp[8][1<<8];\n int ans = 0;\n int dfs(vector<vector<int>>& students, vector<vector<int>>&mentors, int idx, int mask){\n if(idx == students.size()) return 0;\n if(dp[idx][mask]!=-1)return dp[idx][mask]; \n int ans = 0;\n for(int i = 0; i < mentors... | 6 | 1 | ['Dynamic Programming', 'C', 'Bitmask'] | 1 |
maximum-compatibility-score-sum | [python] Simple solution using itertools.permutations() | python-simple-solution-using-itertoolspe-ius7 | Since this was originally a contest problem, we want to find a solution that\'s simple to code.\n\nFirst thing to do is look at the constraints and when we do w | kosievdmerwe | NORMAL | 2021-07-25T04:21:36.662453+00:00 | 2021-07-28T16:25:24.270532+00:00 | 547 | false | Since this was originally a contest problem, we want to find a solution that\'s simple to code.\n\nFirst thing to do is look at the constraints and when we do we notice that both m and n are at most 8. When the constraints are this small (less than 10/11) this means we can likely use a factorial time solution (or a pol... | 6 | 0 | ['Python'] | 0 |
maximum-compatibility-score-sum | C++ simple dp solution | c-simple-dp-solution-by-santhan_ch-gfdg | \n\n\nclass Solution {\npublic:\n int dp[10];\n int comp(vector<vector<int>>& students, vector<vector<int>>& mentors,int i,int j){\n int k,l,count=0 | santhan_ch | NORMAL | 2021-07-25T04:01:00.453136+00:00 | 2021-09-13T16:01:14.500588+00:00 | 440 | false | \n\n```\nclass Solution {\npublic:\n int dp[10];\n int comp(vector<vector<int>>& students, vector<vector<int>>& mentors,int i,int j){\n int k,l,count=0;\n for( k=0;k<students[i].size();k++){\n if(students[i][k]==mentors[j][k])\n count++;\n }\n return count;\n ... | 6 | 0 | [] | 1 |
maximum-compatibility-score-sum | [Python3] Bitmask DP - Detailed Explanation | python3-bitmask-dp-detailed-explanation-00ayw | Intuition\n- Each student we try all possible mentor left. the total score of current student i depend on the choice of the previous mentor choice of student i | dolong2110 | NORMAL | 2024-09-12T15:02:03.594944+00:00 | 2024-09-12T15:02:03.594986+00:00 | 314 | false | # Intuition\n- Each student we try all possible mentor left. the total score of current student `i` depend on the choice of the previous mentor choice of student `i - 1`. It means we have explore all possible cases and which are overlap in states and find the maximum of score -> the signal of DP\n- `m` and `n` is very ... | 5 | 0 | ['Array', 'Dynamic Programming', 'Backtracking', 'Bit Manipulation', 'Bitmask', 'Python3'] | 0 |
maximum-compatibility-score-sum | Go solution with backtracking | go-solution-with-backtracking-by-tuanbie-6pqj | \nfunc maxCompatibilitySum(students [][]int, mentors [][]int) int {\n result, m, mentorVisit := int(0), len(students), make([]bool, len(students))\n \n | tuanbieber | NORMAL | 2022-09-03T14:24:35.226766+00:00 | 2022-09-03T14:26:12.898029+00:00 | 468 | false | ```\nfunc maxCompatibilitySum(students [][]int, mentors [][]int) int {\n result, m, mentorVisit := int(0), len(students), make([]bool, len(students))\n \n var backtrack func(int, int)\n backtrack = func(index int, currentCompatibility int) {\n if index == m {\n result = max(result, current... | 5 | 0 | ['Backtracking', 'Recursion', 'Go'] | 1 |
maximum-compatibility-score-sum | C++ | Recursive DP | Bitmasking | 3ms | 10 MB | Beats 99.62% | c-recursive-dp-bitmasking-3ms-10-mb-beat-nerq | \n\n\nint score[8][8];\nint dp[8][1<<8];\nint n;\nint backtrack(int i, int mask){\n\tif(i==n) return 0;\n\tif(dp[i][mask]!=-1) return dp[i][mask];\n\tint ret=IN | raiaankur1 | NORMAL | 2022-06-28T19:01:43.169557+00:00 | 2022-06-28T19:01:43.169610+00:00 | 514 | false | \n\n```\nint score[8][8];\nint dp[8][1<<8];\nint n;\nint backtrack(int i, int mask){\n\tif(i==n) return 0;\n\tif(dp[i][mask]!=-1) return dp[i][mask];\n\tint ret=INT_MIN;\n\tfor(int j=0; j<n; j++)\n\t\tif(mask&(... | 4 | 0 | ['Dynamic Programming', 'Recursion', 'C', 'Bitmask', 'C++'] | 1 |
maximum-compatibility-score-sum | C++ || Backtracking || Commented || faster than 100% | c-backtracking-commented-faster-than-100-a9ag | For every student try to pair it with every mentor, and for all these combinations, save the maximum resultant.\n\nclass Solution {\npublic:\n \nvoid find(ve | sahiltuli_31 | NORMAL | 2021-07-25T05:52:41.775786+00:00 | 2021-07-25T05:56:56.730908+00:00 | 296 | false | For every student try to pair it with every mentor, and for all these combinations, save the maximum resultant.\n```\nclass Solution {\npublic:\n \nvoid find(vector<vector<int> > &students,vector<vector<int >> &mentors,int st,int n,vector<int> &used,int &temp,int &ans)\n{\n if(st == n)\n {\n ans = max(a... | 4 | 0 | ['Backtracking', 'C++'] | 0 |
maximum-compatibility-score-sum | Very simple c++ code with all possible combinations. Simply use of stl. | very-simple-c-code-with-all-possible-com-xi18 | \n// As m and n are too small so that we can check every possible combination.\n// As it hard to shuffle complete so just use their indexes. And with stl functi | abaddu_21 | NORMAL | 2021-07-25T04:37:14.084606+00:00 | 2021-07-25T05:08:46.270608+00:00 | 346 | false | ```\n// As m and n are too small so that we can check every possible combination.\n// As it hard to shuffle complete so just use their indexes. And with stl function permutation\n// check ans with next permutation. Continue till all permutation done.\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector... | 4 | 0 | ['C'] | 1 |
maximum-compatibility-score-sum | DP with Bitmasking Easy Intuititive || C++ | dp-with-bitmasking-easy-intuititive-c-by-p5xz | Explanation and intuition :\n At first, the noticing fact are the problem contraints. Both m and n are less than or equals to 8.\n Also, we have to keep a track | dikbhranto_dishari | NORMAL | 2023-06-13T03:25:05.810662+00:00 | 2023-06-13T03:26:34.987681+00:00 | 227 | false | **Explanation and intuition** :\n* At first, the noticing fact are the problem contraints. Both m and n are less than or equals to 8.\n* Also, we have to keep a track of the subset from the mentors array who have been already assigned to a particular student (can be done in the other way too).\n* Thus, these facts enha... | 3 | 0 | ['Dynamic Programming', 'C++'] | 1 |
maximum-compatibility-score-sum | Permutations | Backtracking | C++ | permutations-backtracking-c-by-tusharbha-9wpe | \nclass Solution {\n void dfs(int i, int n, int m, vector<vector<int>>& students, vector<vector<int>>& mentors, int &ans) {\n if(i == n) {\n | TusharBhart | NORMAL | 2023-03-20T15:12:37.023390+00:00 | 2023-03-20T15:12:37.023420+00:00 | 914 | false | ```\nclass Solution {\n void dfs(int i, int n, int m, vector<vector<int>>& students, vector<vector<int>>& mentors, int &ans) {\n if(i == n) {\n int cnt = 0;\n for(int j=0; j<n; j++) {\n for(int k=0; k<m; k++) cnt += students[j][k] == mentors[j][k];\n }\n ... | 3 | 0 | ['Backtracking', 'C++'] | 0 |
maximum-compatibility-score-sum | c++ | easy | short | c-easy-short-by-akshat0610-rars | \nclass Solution {\npublic:\n int ans=INT_MIN;\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) \n {\n int | akshat0610 | NORMAL | 2022-10-21T08:51:13.435902+00:00 | 2022-10-21T08:51:13.435940+00:00 | 757 | false | ```\nclass Solution {\npublic:\n int ans=INT_MIN;\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) \n {\n int idx=0;\n int n=students.size();\n vector<bool>vis(n,false);\n int currscore=0;\n fun(idx,students,mentors,n,vis,currscore);\n ... | 3 | 0 | ['Dynamic Programming', 'Backtracking', 'Depth-First Search', 'Recursion', 'C', 'C++'] | 1 |
maximum-compatibility-score-sum | C++||Backtracking ||Recursive||Easy to Understand | cbacktracking-recursiveeasy-to-understan-1k1d | ```\nclass Solution {\npublic:\n int ans=0;\n void backtrack(vector>& students, vector>& mentors,int idx,int curr_res,vector &vis)\n {\n if(idx> | return_7 | NORMAL | 2022-07-16T06:23:10.504286+00:00 | 2022-07-16T06:23:10.504320+00:00 | 322 | false | ```\nclass Solution {\npublic:\n int ans=0;\n void backtrack(vector<vector<int>>& students, vector<vector<int>>& mentors,int idx,int curr_res,vector<int> &vis)\n {\n if(idx>=mentors.size())\n {\n ans=max(ans,curr_res);\n return ;\n }\n for(int i=0;i<student... | 3 | 0 | ['Backtracking', 'Recursion', 'C'] | 0 |
maximum-compatibility-score-sum | [Python] | python-by-rahulranjan95-iwiz | \nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n res = [-1]\n visited = [False] | rahulranjan95 | NORMAL | 2021-09-03T05:48:54.844241+00:00 | 2021-09-03T05:49:39.674474+00:00 | 353 | false | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n res = [-1]\n visited = [False]*len(students)\n #ssf ===> score so far\n #res ==> final result. It is a list as it acts as a global variable\n #idx ====> index over st... | 3 | 0 | ['Backtracking', 'Recursion', 'Python', 'Python3'] | 0 |
maximum-compatibility-score-sum | [C++] Backtracking Solution, faster than 100% | c-backtracking-solution-faster-than-100-w1ra1 | The idea is simple :-\n1) I made a 2D matrix of size MM for every possible combination.\n2) then find "Maximum sum of a Matrix where each value is from a unique | shubhamrgh | NORMAL | 2021-07-25T10:28:01.552117+00:00 | 2021-07-25T10:45:25.437150+00:00 | 242 | false | The idea is simple :-\n1) I made a 2D matrix of size M*M for every possible combination.\n2) then find "Maximum sum of a Matrix where each value is from a unique row and column".\n\n```\nclass Solution {\npublic:\n vector<int> col;\n int mx = INT32_MIN;\n void maxSum(int n, vector<vector<int>> &matrix, int idx... | 3 | 0 | ['Backtracking', 'C'] | 0 |
maximum-compatibility-score-sum | Naive Brute Force Using next_permutation(68ms) | naive-brute-force-using-next_permutation-dwom | Here is a pretty naive implementation ,hope it helps\n```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector>& student, vector>& mentors) {\n | amardeepganguly | NORMAL | 2021-07-25T04:05:53.569214+00:00 | 2021-07-25T04:09:48.491328+00:00 | 189 | false | Here is a pretty naive implementation ,hope it helps\n```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& student, vector<vector<int>>& mentors) {\n int m=student.size();\n int n=student[0].size();\n //This matrix com stores the compatibility score between i th student ... | 3 | 0 | ['C'] | 1 |
maximum-compatibility-score-sum | Java | Simple DFS | Check all permutations | java-simple-dfs-check-all-permutations-b-tzlx | \nclass Solution {\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n return dfs(students,mentors,new boolean[mentors.length],0); | Sans26 | NORMAL | 2021-07-25T04:02:49.234844+00:00 | 2021-07-25T04:03:46.893483+00:00 | 599 | false | ```\nclass Solution {\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n return dfs(students,mentors,new boolean[mentors.length],0);\n }\n int dfs(int[][] s,int[][] m,boolean[] b,int o){\n int sum=0;\n if(o==s.length){\n return 0;\n }\n for(int... | 3 | 1 | ['Depth-First Search', 'Java'] | 0 |
maximum-compatibility-score-sum | [c++] next_permutation solution. | c-next_permutation-solution-by-mahmoud_w-fkpu | \'\'\'\n\nclass Solution {\npublic:\n int maxCompatibilitySum(vector>& students, vector>& mentors) {\n\t\n int m = students.size() ; // number o | Mahmoud_Warrak | NORMAL | 2021-07-25T04:02:13.304232+00:00 | 2021-07-25T04:10:03.344784+00:00 | 268 | false | \'\'\'\n\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n\t\n int m = students.size() ; // number of students\n int n = students[0].size() ; // number of questions\n int chos[m] ; // this array select... | 3 | 1 | [] | 0 |
maximum-compatibility-score-sum | Bitmask DP | JAVA | bitmask-dp-java-by-drashta01-uqkj | \n\nclass Solution {\n Integer[][]dp;\n int m, n;\n int[][] S;\n int[][] M;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) { | drashta01 | NORMAL | 2021-07-25T04:00:54.630249+00:00 | 2021-07-25T04:00:54.630294+00:00 | 234 | false | ```\n\nclass Solution {\n Integer[][]dp;\n int m, n;\n int[][] S;\n int[][] M;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n m = students.length;\n n = students[0].length;\n S = students;\n M = mentors;\n dp = new Integer[m][1 << 8];\n r... | 3 | 0 | [] | 0 |
maximum-compatibility-score-sum | Unlock the Secret to Maximizing Compatibility Scores with This Genius Algorithm! 🚀🔥 | unlock-the-secret-to-maximizing-compatib-pfo0 | IntuitionThe problem requires finding the best pairing between students and mentors to maximize the compatibility score.
Since the number of students/mentors is | ishaan2003 | NORMAL | 2025-02-28T13:38:04.004561+00:00 | 2025-02-28T13:38:04.004561+00:00 | 115 | false | # Intuition
The problem requires finding the best pairing between students and mentors to maximize the compatibility score.
Since the number of students/mentors is small (≤ 8), we can use backtracking to explore all possible assignments efficiently.
# Approach
1. Use backtracking to generate all permutations of st... | 2 | 0 | ['C++'] | 0 |
maximum-compatibility-score-sum | Backtracking + Recursive Approach with Detail Explanation || Beginner Friendly | backtracking-recursive-approach-with-det-6nbn | Code\n\nclass Solution {\n int max;\n\n private void solveBacktrack(int[][] students, int[][] mentors, int pos, int score, boolean[] vis) {\n // Ba | Shree_Govind_Jee | NORMAL | 2024-02-01T16:17:56.264306+00:00 | 2024-02-01T16:17:56.264341+00:00 | 314 | false | # Code\n```\nclass Solution {\n int max;\n\n private void solveBacktrack(int[][] students, int[][] mentors, int pos, int score, boolean[] vis) {\n // Base Case\n if (pos >= students.length) {\n max = Math.max(max, score);\n return;\n }\n\n // Recursive Approach St... | 2 | 0 | ['Array', 'Dynamic Programming', 'Backtracking', 'Bit Manipulation', 'Recursion', 'Bitmask', 'Java'] | 0 |
maximum-compatibility-score-sum | Recursion Solution | recursion-solution-by-20ce01050-m7t6 | Intuition\nInitially, I considered a greedy approach for solving the problem, where I would always chreoose the maximum compatibility score. However, I realized | 20ce01050 | NORMAL | 2023-09-15T08:34:13.948071+00:00 | 2023-09-15T08:34:13.948099+00:00 | 135 | false | # Intuition\nInitially, I considered a greedy approach for solving the problem, where I would always chreoose the maximum compatibility score. However, I realized that this approach may not yield the correct result. Instead, I decided to adopt a recursive approach to solve the problem.\n<!-- Describe your first thought... | 2 | 0 | ['Recursion', 'C++'] | 0 |
maximum-compatibility-score-sum | Easy C++ Solution || Bitmask + DP || 100% Faster ✔✔ | easy-c-solution-bitmask-dp-100-faster-by-ytck | \n\n# Code\n\nclass Solution {\npublic:\n int dp[8][256];\n int calcSum(vector<int> &v1,vector<int> &v2){\n int cnt=0;\n for(int i=0;i<v1.si | mamatva004 | NORMAL | 2023-06-19T13:56:53.296861+00:00 | 2023-06-19T13:56:53.296889+00:00 | 755 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int dp[8][256];\n int calcSum(vector<int> &v1,vector<int> &v2){\n int cnt=0;\n for(int i=0;i<v1.size();i++) cnt+=(v1[i]==v2[i]);\n return cnt;\n }\n int help(int idx,int mask, vector<vector<int>>& students, vector<vector<int>>& mentors,int m)... | 2 | 0 | ['Dynamic Programming', 'Bitmask', 'C++'] | 1 |
maximum-compatibility-score-sum | Easy Brute Force Accepted | easy-brute-force-accepted-by-sanket_jadh-ha1e | ```\nclass Solution {\npublic:\n int count(int i,int j,vector>&s,vector>&m){\n int ct=0;\n for(int k=0;k<s[i].size();k++){\n if(s[i] | Sanket_Jadhav | NORMAL | 2022-08-20T06:32:35.065432+00:00 | 2022-08-20T06:32:35.065458+00:00 | 376 | false | ```\nclass Solution {\npublic:\n int count(int i,int j,vector<vector<int>>&s,vector<vector<int>>&m){\n int ct=0;\n for(int k=0;k<s[i].size();k++){\n if(s[i][k]==m[j][k])ct++;\n }\n \n return ct;\n }\n \n int func(int i,vector<int>&vis,vector<vector<int>>&st,vect... | 2 | 0 | ['Recursion', 'C++'] | 0 |
maximum-compatibility-score-sum | [C++] : From Backtracking to DP + Bit masking | c-from-backtracking-to-dp-bit-masking-by-0430 | Approch 1 : Using Backtracking\n\nclass Solution {\npublic:\n \n int calculate_score(vector<int> &a, vector<int> &b)\n {\n int ans = 0;\n | zanhd | NORMAL | 2022-04-09T17:03:56.295620+00:00 | 2022-04-10T14:23:19.827575+00:00 | 166 | false | Approch 1 : Using Backtracking\n```\nclass Solution {\npublic:\n \n int calculate_score(vector<int> &a, vector<int> &b)\n {\n int ans = 0;\n for(int i = 0; i < a.size(); i++)\n {\n ans += (a[i] == b[i]);\n }\n return ans;\n }\n \n int mx_sum(int i, vector<... | 2 | 0 | ['Backtracking'] | 1 |
maximum-compatibility-score-sum | Python 3, one line | python-3-one-line-by-l1ne-p2lu | There\'s only a max of 8 students and mentors, so we can just try every permutation. Easy peasy.\n\npython\nclass Solution:\n def maxCompatibilitySum(self, S, | l1ne | NORMAL | 2021-08-15T05:28:28.691075+00:00 | 2021-08-15T05:30:12.362933+00:00 | 192 | false | There\'s only a max of 8 students and mentors, so we can just try every permutation. Easy peasy.\n\n```python\nclass Solution:\n def maxCompatibilitySum(self, S, M):\n return max(sum(sum(map(eq, *z)) for z in zip(S, P)) for P in permutations(M))\n``` | 2 | 0 | [] | 1 |
maximum-compatibility-score-sum | Python Bitmask Memoization Solution | python-bitmask-memoization-solution-by-2-dwe0 | \nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n n = len(students)\n m = len(st | 2019csb1077 | NORMAL | 2021-08-14T05:15:27.249710+00:00 | 2021-08-14T05:15:27.249745+00:00 | 117 | false | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n n = len(students)\n m = len(students[0])\n full = 1<<n\n dp = [[-1 for i in range(full)] for j in range(n)]\n def rec(mentorMask, studentIndex):\n if mento... | 2 | 0 | [] | 0 |
maximum-compatibility-score-sum | [C++] STL - next_permutation() | c-stl-next_permutation-by-harshit_2000-7quv | The brute force solution is generating all the permuntations of the students and calculates the score of this permutation and the students.\nTime Complexity : O | harshit_2000 | NORMAL | 2021-08-07T06:27:41.290523+00:00 | 2021-08-07T06:27:41.290569+00:00 | 140 | false | The brute force solution is generating all the permuntations of the students and calculates the score of this permutation and the students.\nTime Complexity : ``` O(n! * nm) ``` **n!** for permutations and **nm** for calculating score.\nSince , ``` n, m <= 8 ``` and ``` 8! * 8 * 8 == 2,580,480 ``` which should pass.... | 2 | 0 | [] | 1 |
maximum-compatibility-score-sum | Python - Simple DFS solution | python-simple-dfs-solution-by-ajith6198-gy21 | \nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n \n n, m = len(students), len(s | ajith6198 | NORMAL | 2021-08-03T04:30:57.256693+00:00 | 2021-08-03T04:31:15.605250+00:00 | 368 | false | ```\nclass Solution:\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n \n n, m = len(students), len(students[0])\n out = []\n\t\t\n def dfs(i, used, score):\n \n if i == n:\n out.append(score)\n ... | 2 | 0 | ['Depth-First Search', 'Python'] | 2 |
maximum-compatibility-score-sum | C++ with comments #bitmask #DP #easy | c-with-comments-bitmask-dp-easy-by-elcam-43rx | \n int dp[9][265];\n\t// function to calculate value for some matrix a of students and other matrix b of mentors --- \n\t\t\t\t\t// a == students[i] && b | elcamino10 | NORMAL | 2021-07-28T13:22:49.576573+00:00 | 2021-07-28T13:26:32.593618+00:00 | 141 | false | ```\n int dp[9][265];\n\t// function to calculate value for some matrix a of students and other matrix b of mentors --- \n\t\t\t\t\t// a == students[i] && b == mentors[j] \n int ch(vector<int> a, vector<int> b){\n int n=a.size(),ans=0;\n for(int i=0;i<n;i++){\n if(a[i]==b[i])\n ... | 2 | 0 | ['Dynamic Programming', 'Bitmask'] | 2 |
maximum-compatibility-score-sum | 1ms 100% JAVA BackTracking + BitMask solution | 1ms-100-java-backtracking-bitmask-soluti-fpli | \n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int n = students.length;\n return helper(0, 0, students, m | chenzuojing | NORMAL | 2021-07-28T01:13:42.186439+00:00 | 2021-07-28T01:13:59.966478+00:00 | 115 | false | ```\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int n = students.length;\n return helper(0, 0, students, mentors, new Integer[n][1 << n]);\n }\n\n\n private int helper(int pos, int mask, int[][] students, int[][] mentors, Integer[][] memo) {\n ... | 2 | 0 | [] | 1 |
maximum-compatibility-score-sum | C++ Solution using Permutation | c-solution-using-permutation-by-smritina-ig0j | \nclass Solution {\npublic:\n int cal(vector<vector<int>> &mentors, vector<vector<int>> &students)\n {\n int n=students.size(),m=students[0].size(),s | smritinaik1421 | NORMAL | 2021-07-27T10:17:39.431256+00:00 | 2021-07-27T10:17:39.431299+00:00 | 91 | false | ```\nclass Solution {\npublic:\n int cal(vector<vector<int>> &mentors, vector<vector<int>> &students)\n {\n int n=students.size(),m=students[0].size(),sum=0;\n \n for(int i=0;i<n;i++)\n {\n for(int j=0;j<m;j++)\n {\n sum+=(students[i][j]==mentors[i][j])?1:0;\n ... | 2 | 0 | [] | 1 |
maximum-compatibility-score-sum | C++ | Backtracking | Beginner friendly | c-backtracking-beginner-friendly-by-yash-agnv | Since constraints were very small\n\nm == students.length == mentors.length\nn == students[i].length == mentors[j].length\n1 <= m, n <= 8\nstudents[i][k] is eit | yashporwal11 | NORMAL | 2021-07-27T07:31:56.559528+00:00 | 2021-07-30T16:06:48.022747+00:00 | 123 | false | Since constraints were very small\n```\nm == students.length == mentors.length\nn == students[i].length == mentors[j].length\n1 <= m, n <= 8\nstudents[i][k] is either 0 or 1.\nmentors[j][k] is either 0 or 1.\n```\n\nthat\'s why I decided to go with the backtracking approach.\n\n```\nclass Solution {\npublic:\n\t// to c... | 2 | 0 | [] | 2 |
maximum-compatibility-score-sum | C++ | Faster than 100% | Backtracking and Bit Mask | Comments Added | c-faster-than-100-backtracking-and-bit-m-vkks | We calculate compatibility between every student and mentor. Since the number of mentors and students are capped at 8, we can check every possible combination o | kaushal7797 | NORMAL | 2021-07-25T18:10:20.391607+00:00 | 2021-07-25T18:10:20.391654+00:00 | 71 | false | We calculate compatibility between every student and mentor. Since the number of mentors and students are capped at 8, we can check every possible combination of mentor and student. To keep a track of mentor assigned to student, we use bit masking.\n\nRefer to the code below for the above approach - \n\n```\nclass Solu... | 2 | 0 | [] | 0 |
maximum-compatibility-score-sum | My very slow (4224ms!!) brute force (Python) | my-very-slow-4224ms-brute-force-python-b-hkcx | This is my very slow, but lovely brute force solution.\nIt\'s so straightforward, so I think it\'s self-explanatory.\n\n\nfrom itertools import permutations\n\n | kryuki | NORMAL | 2021-07-25T05:40:41.366353+00:00 | 2021-08-02T21:41:37.569402+00:00 | 42 | false | This is my very slow, but lovely brute force solution.\nIt\'s so straightforward, so I think it\'s self-explanatory.\n\n```\nfrom itertools import permutations\n\nclass Solution:\n def maxCompatibilitySum(self, students, mentors) -> int:\n def calc(lst1, lst2):\n res = 0\n for num1, num2... | 2 | 0 | [] | 0 |
maximum-compatibility-score-sum | Easy | Backtracking Solution | easy-backtracking-solution-by-kritikpanc-v5gm | \n\t class Solution {\n\t\t public:\n\t\t\tvoid sol( vector>& arr ,unordered_set&vis , int row , int count , int &ans){\n\t\t\t\tif(row == arr.size()){\n\t\t\t | kritikpancholi | NORMAL | 2021-07-25T04:03:01.148370+00:00 | 2021-07-25T04:03:01.148402+00:00 | 178 | false | \n\t class Solution {\n\t\t public:\n\t\t\tvoid sol( vector<vector<int>>& arr ,unordered_set<int>&vis , int row , int count , int &ans){\n\t\t\t\tif(row == arr.size()){\n\t\t\t\t\tans = max(count ,ans );\n\t\t\t\t\treturn ; \n \n }\n \n for(int i = 0;i<arr[0].size();i++){\n ... | 2 | 1 | [] | 0 |
maximum-compatibility-score-sum | Backtracking with Dp and Bit Manipulation || explanation in comments || C++ | backtracking-with-dp-and-bit-manipulatio-ytm4 | \nclass Solution {\npublic:\n int dp[10][18000];\n int helper(int idx,int taken,vector<vector<int>>& student,vector<vector<int>>& mentor)\n {\n | tejpratapp468 | NORMAL | 2021-07-25T04:02:23.280881+00:00 | 2021-07-25T04:06:21.364571+00:00 | 129 | false | ```\nclass Solution {\npublic:\n int dp[10][18000];\n int helper(int idx,int taken,vector<vector<int>>& student,vector<vector<int>>& mentor)\n {\n if(idx>=student.size()) return 0;\n if(dp[idx][taken]!=-1) return dp[idx][taken];\n int ans=-1e8;\n for(int i=0;i<student.size();i++)\n... | 2 | 1 | [] | 0 |
maximum-compatibility-score-sum | Permutation of `m`, with explanation | permutation-of-m-with-explanation-by-ryz-0ctw | Thought process:\nFind match of students and mentors is the same as keep students in original order, but match them with permutated mentors order.\ni.e. m = 3, | ryz | NORMAL | 2021-07-25T04:02:21.853964+00:00 | 2021-07-25T04:11:21.607613+00:00 | 162 | false | Thought process:\nFind match of students and mentors is the same as keep students in original order, but match them with permutated mentors order.\ni.e. m = 3, perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1]]\n\nTime: O(m! + m!*n*m)\nSpace: O(m!)\n\n```\nclass Solution(object):\n def maxCom... | 2 | 0 | [] | 0 |
maximum-compatibility-score-sum | Backtracking | Easy to Understand | backtracking-easy-to-understand-by-ghozt-1l8e | Code | ghozt777 | NORMAL | 2025-03-05T13:12:53.528680+00:00 | 2025-03-05T13:13:42.388467+00:00 | 83 | false | # Code
```cpp []
class Solution {
int cal_max_score(vector<vector<int>> &scores, int i = 0){
static unordered_set<int> used_mentors ;
if(i >= scores.size()) return 0 ;
int res = 0 ;
for(int j = 0 ; j < scores[i].size() ; j++){
if(used_mentors.find(j) != used_mentors.end()... | 1 | 0 | ['Backtracking', 'C++'] | 0 |
maximum-compatibility-score-sum | Python 3: TC O(m 2**m), SC O(2**m): DFS+BT optimized to DFS+Caching | python-3-tc-om-2m-sc-o2m-dfsbt-optimized-rg4r | Intuition\n\n## Brute Force\n\nThe brute force answer to pretty much all "what\'s the best matching?" problems is to literally try all possible pairings, with D | biggestchungus | NORMAL | 2024-08-01T23:58:24.437952+00:00 | 2024-08-01T23:58:24.437980+00:00 | 53 | false | # Intuition\n\n## Brute Force\n\nThe brute force answer to pretty much all "what\'s the best matching?" problems is to literally try all possible pairings, with DFS + backtracking. It works pretty well.\n\nDFS + backtracking is a very good technique to know really well. It shows up in a lot of problems. And learning it... | 1 | 0 | ['Python3'] | 1 |
maximum-compatibility-score-sum | No Bitmask, No DP, No Recursion, Just Pure Permutation (as given in hints) | no-bitmask-no-dp-no-recursion-just-pure-5eki5 | This is a tricky problem since one doesn\'t (at least I) think about permutations when dealing with variations. However, proceedings on the lines of "Minimum Fa | miho_nishizumi | NORMAL | 2024-05-02T14:44:08.653398+00:00 | 2024-05-03T17:02:19.149198+00:00 | 136 | false | This is a tricky problem since one doesn\'t (at least I) think about permutations when dealing with variations. However, proceedings on the lines of "[Minimum Falling Path Sum II](https://leetcode.com/problems/minimum-falling-path-sum-ii/)" encounters failure, as additional data structures make the intermittently-worki... | 1 | 0 | ['C', 'Probability and Statistics'] | 1 |
maximum-compatibility-score-sum | My simple Dp+Bitmask Memoized Solution--Self Explanatory code | my-simple-dpbitmask-memoized-solution-se-8vm7 | \n\n# Code\n\nclass Solution {\npublic:\nint dp[10][1024];\nint compat(vector<int>&s,vector<int>&m){\n int res=0;\n for(int i=0;i<s.size();i++){\n | shashank290604 | NORMAL | 2023-10-14T23:20:10.578988+00:00 | 2023-10-14T23:20:10.579016+00:00 | 126 | false | \n\n# Code\n```\nclass Solution {\npublic:\nint dp[10][1024];\nint compat(vector<int>&s,vector<int>&m){\n int res=0;\n for(int i=0;i<s.size();i++){\n if(s[i]==m[i])res++;\n }\n return res;\n}\nint rec(vector<vector<int>>& students, vector<vector<int>>& mentors,int ind,int mask){\nif(ind>=students.siz... | 1 | 0 | ['C++'] | 0 |
maximum-compatibility-score-sum | ✅✔️Easy to understand C++ Solution using Backtracking ✈️✈️✈️✈️✈️ | easy-to-understand-c-solution-using-back-atr9 | 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 | ajay_1134 | NORMAL | 2023-07-07T06:28:31.902093+00:00 | 2023-07-07T06:28:31.902117+00:00 | 289 | 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)$$ --... | 1 | 0 | ['Array', 'Dynamic Programming', 'Backtracking', 'C++'] | 0 |
maximum-compatibility-score-sum | Python, brute force dfs/bitmask dp solution with explanation | python-brute-force-dfsbitmask-dp-solutio-453n | backtrack (permutation)\nlist all permutation of student to enumearte all of student-teacher pairs.\n### python\npython\n\'\'\'\nPrecalculate the score for each | shun6096tw | NORMAL | 2023-03-17T07:15:32.441583+00:00 | 2023-09-11T07:56:36.492255+00:00 | 43 | false | ### backtrack (permutation)\nlist all permutation of student to enumearte all of student-teacher pairs.\n### python\n```python\n\'\'\'\nPrecalculate the score for each student-teacher pairing, and enumerate all of the pairing using permutation to find max score\ntc is O(n * (m^2) + m * m!), sc is O(m^2)\n\'\'\'\nclass ... | 1 | 0 | ['Backtracking', 'C', 'Bitmask', 'Python'] | 0 |
maximum-compatibility-score-sum | c++ | easy | short | c-easy-short-by-venomhighs7-4964 | \n# Code\n\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n\tint ans = 0;\n\tvector<int> | venomhighs7 | NORMAL | 2022-10-14T04:13:30.643782+00:00 | 2022-10-14T04:13:30.643839+00:00 | 197 | false | \n# Code\n```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n\tint ans = 0;\n\tvector<int> pos;\n\tfor(int i=0;i<students.size();i++) pos.push_back(i);\n\tdo{\n\t\tint curr = 0;\n\t\tfor(int i = 0;i<students.size(); i++)\n\t\t\tfor(int j=0;j<stude... | 1 | 1 | ['C++'] | 0 |
maximum-compatibility-score-sum | ✅✅C++ || Permutation || Easy to Understand || Backtracking | c-permutation-easy-to-understand-backtra-eidy | \nclass Solution {\npublic:\n vector<int>visited;\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int n | tamim447 | NORMAL | 2022-09-30T15:48:09.784692+00:00 | 2022-11-01T16:34:16.503739+00:00 | 356 | false | ```\nclass Solution {\npublic:\n vector<int>visited;\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int n = students.size();\n int m = students[0].size();\n visited.resize(n+1, 0);\n return permutation(students, mentors, 0, n, m);\n }\n ... | 1 | 0 | ['Backtracking', 'C'] | 1 |
maximum-compatibility-score-sum | ✅✅Faster || Easy To Understand || C++ Code | faster-easy-to-understand-c-code-by-__kr-51m6 | Backtracking\n\n Time Complexity :- O(N * N!)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n \n int calculate(vector<vector<int>>& students | __KR_SHANU_IITG | NORMAL | 2022-09-12T06:45:42.812487+00:00 | 2022-09-12T06:45:42.812530+00:00 | 441 | false | * ***Backtracking***\n\n* ***Time Complexity :- O(N * N!)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n \n int calculate(vector<vector<int>>& students, vector<vector<int>>& mentors, vector<int>& arr)\n {\n int n = students.size();\n \n // find the compatability... | 1 | 0 | ['Backtracking', 'C', 'C++'] | 0 |
maximum-compatibility-score-sum | Easy recursion+bitmask+memoization | easy-recursionbitmaskmemoization-by-aksh-52z7 | \nclass Solution {\npublic:\n int dp[9][1<<9];\n int n,m;\n int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& ma) {\n m=s.siz | akshatsaxena2017 | NORMAL | 2022-08-08T06:22:34.791542+00:00 | 2022-08-08T06:22:34.791582+00:00 | 117 | false | ```\nclass Solution {\npublic:\n int dp[9][1<<9];\n int n,m;\n int maxCompatibilitySum(vector<vector<int>>& s, vector<vector<int>>& ma) {\n m=s.size(),n=ma[0].size();\n memset(dp,-1,sizeof(dp));\n return fun(m,0,s,ma);\n }\n int fun(int i,int mask,vector<vector<int>>& s,vector<vector... | 1 | 0 | ['Dynamic Programming', 'C'] | 0 |
maximum-compatibility-score-sum | Easy to Understand C++ solution | easy-to-understand-c-solution-by-ishank1-0261 | \nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n \n vector<int> stuMask;\ | ishank193aggarwal | NORMAL | 2022-07-07T17:23:32.402273+00:00 | 2022-07-07T17:23:32.402342+00:00 | 59 | false | ```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n \n vector<int> stuMask;\n vector<int> menMask;\n \n for(int i=0;i<students.size();i++){\n int mask=0;\n for(int j=0;j<students[i].size();j... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | C++ || DP+Bitmask | c-dpbitmask-by-m_sahil_kumar-gbht | \nclass Solution {\npublic:\n int dp[9][(1<<8)+1];\n int n,m;\n\n int rec(int lev,int mask,vector<vector<int>>& st, vector<vector<int>>& mt){\n | M_sahil_kumar | NORMAL | 2022-06-21T11:47:18.446500+00:00 | 2022-06-21T11:47:18.446541+00:00 | 88 | false | ```\nclass Solution {\npublic:\n int dp[9][(1<<8)+1];\n int n,m;\n\n int rec(int lev,int mask,vector<vector<int>>& st, vector<vector<int>>& mt){\n if(lev==n) return 0;\n if(dp[lev][mask]!=-1) return dp[lev][mask];\n int ans=0;\n for(int i=0;i<n;i++){\n \n if(!(... | 1 | 0 | ['Dynamic Programming', 'Bitmask'] | 0 |
maximum-compatibility-score-sum | [Python] DP bitmask with explanation (faster than 92%) | python-dp-bitmask-with-explanation-faste-xf4n | Solution from @ye15 https://leetcode.com/problems/maximum-compatibility-score-sum/discuss/1360746/Python3-permutations\n\nBut I use dp dict instead of python @c | woflow | NORMAL | 2022-04-07T07:30:54.260183+00:00 | 2022-04-07T07:43:47.258459+00:00 | 107 | false | Solution from @ye15 https://leetcode.com/problems/maximum-compatibility-score-sum/discuss/1360746/Python3-permutations\n\nBut I use dp dict instead of python @cache decorator.\nIt took me a while to understand the solution. So I want to write an explantaion to save some time for other.\n\nFirst step is easy. Calculate ... | 1 | 0 | ['Dynamic Programming', 'Bitmask'] | 0 |
maximum-compatibility-score-sum | C++ solution with explanation faster than 80% | c-solution-with-explanation-faster-than-d6ckr | \n//We have m different students and m different mentors. So, there are m! different ways of mapping students\n//with the mentors. This is what I\'ve done and a | Ani2424 | NORMAL | 2022-02-17T16:00:59.468423+00:00 | 2022-02-22T06:54:41.021725+00:00 | 88 | false | ```\n//We have m different students and m different mentors. So, there are m! different ways of mapping students\n//with the mentors. This is what I\'ve done and at last took the maximum of it. This is kind of brute force but \n//before that I converted every row to a binary number because bitwise operations are very f... | 1 | 0 | [] | 1 |
maximum-compatibility-score-sum | [C++] Recursion + Memorization beats 93% | c-recursion-memorization-beats-93-by-ilo-xdh8 | Time Complexity: O((2^m)nm)\nHelper function if not skipped takes O(mn) and will only be called 2^m times. \n\nclass Solution {\npublic: \n int helper(vec | ilovehawthorn | NORMAL | 2022-02-01T07:25:29.735071+00:00 | 2022-02-01T07:31:49.003908+00:00 | 163 | false | Time Complexity: O((2^m)*n*m)\nHelper function if not skipped takes O(mn) and will only be called 2^m times. \n```\nclass Solution {\npublic: \n int helper(vector<vector<int>>& s, vector<vector<int>>& me, int mask, vector<int>& dp){\n int idx = bitset<8>(mask).count(), m = s.size(), n = s[0].size();\n ... | 1 | 0 | ['Dynamic Programming', 'Memoization', 'C'] | 0 |
maximum-compatibility-score-sum | Backtracking solution || C++ || Easy to understand | backtracking-solution-c-easy-to-understa-7ne0 | ```\nclass Solution {\npublic:\n int check(vector&student,vector&mentor){\n int i=0,sum=0;\n while(i<student.size()){\n if(student[i | Sarthak2512 | NORMAL | 2021-12-27T12:15:14.538793+00:00 | 2021-12-27T12:15:14.538817+00:00 | 113 | false | ```\nclass Solution {\npublic:\n int check(vector<int>&student,vector<int>&mentor){\n int i=0,sum=0;\n while(i<student.size()){\n if(student[i]==mentor[i])sum++;\n i++;\n }\n return sum;\n }\n void solve(vector<vector<int>>&students,vector<vector<int>>&mentors,... | 1 | 0 | ['Backtracking', 'C'] | 0 |
maximum-compatibility-score-sum | C++ | next_permutation | c-next_permutation-by-magzhan-z5jn | \n\tint maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int maxScore = 0;\n \n vector<int> studentId, | magzhan | NORMAL | 2021-10-27T00:15:22.465431+00:00 | 2021-10-27T00:15:22.465469+00:00 | 106 | false | ```\n\tint maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int maxScore = 0;\n \n vector<int> studentId, mentorId;\n for (int i = 0; i < students.size(); i++) {\n studentId.push_back(i);\n mentorId.push_back(i);\n }\n \... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | DP + Bitmask | 0ms Solution | With complete explanation | dp-bitmask-0ms-solution-with-complete-ex-dbd4 | Here in this problem out of all the combinations between students and mentor, we have to find the optimal combination in which the score is maximum.\n\nTo do so | n19 | NORMAL | 2021-08-31T10:35:01.771104+00:00 | 2021-08-31T10:35:38.238952+00:00 | 148 | false | Here in this problem out of all the combinations between students and mentor, we have to find the optimal combination in which the score is maximum.\n\nTo do so we can use recursion to explore all the combinations.\nNow, while doing this we need to maintain track of all the mentors which have already been assigned to s... | 1 | 0 | ['Dynamic Programming', 'Recursion', 'Bitmask'] | 0 |
maximum-compatibility-score-sum | SIMPLE & EASY JAVA Solution | simple-easy-java-solution-by-dyanjno123-irsk | \nclass Solution {\n\tint ans;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int[][] arr = new int[students.length][students | Dyanjno123 | NORMAL | 2021-08-04T03:31:36.647184+00:00 | 2021-08-04T03:31:36.647252+00:00 | 178 | false | ```\nclass Solution {\n\tint ans;\n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n int[][] arr = new int[students.length][students.length];\n for(int i = 0; i < students.length; i++) {\n \tfor(int j = 0; j < mentors.length; j++) {\n \t\tarr[i][j] = find(students[i],... | 1 | 1 | ['Backtracking', 'Java'] | 0 |
maximum-compatibility-score-sum | Scala. Extremely simple, easy to understand and ineffective | scala-extremely-simple-easy-to-understan-hvlv | \n def maxCompatibilitySum(students: Array[Array[Int]], mentors: Array[Array[Int]]): Int =\n search(students.toList, mentors.toSet)\n\n def search(students | nikiforo | NORMAL | 2021-08-01T10:16:02.691145+00:00 | 2021-08-01T10:16:02.691191+00:00 | 82 | false | ```\n def maxCompatibilitySum(students: Array[Array[Int]], mentors: Array[Array[Int]]): Int =\n search(students.toList, mentors.toSet)\n\n def search(students: List[Array[Int]], mentors: Set[Array[Int]]): Int =\n students match {\n case Nil => 0\n case s :: tail => mentors.map(m => compatibility(s, m)... | 1 | 0 | [] | 1 |
maximum-compatibility-score-sum | C# DSF Solution 100%, 120ms, 25MB | c-dsf-solution-100-120ms-25mb-by-robl123-y8hd | public class Solution {\n public int MaxCompatibilitySum(int[][] students, int[][] mentors) \n {\n int rows = students.Length;\n int co | robl123 | NORMAL | 2021-07-30T19:10:50.959221+00:00 | 2021-07-30T19:10:50.959257+00:00 | 103 | false | ```public class Solution {\n public int MaxCompatibilitySum(int[][] students, int[][] mentors) \n {\n int rows = students.Length;\n int cols = students[0].Length;\n\n int[,] compatability = new int[rows, rows];\n\n for (int i = 0; i < rows; i++) //student\n {\n ... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | C++ Easy Brute Force || Using XOR property | c-easy-brute-force-using-xor-property-by-6774 | \nint maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int n = students.size(), m = students[0].size();\n // n | anshjain18 | NORMAL | 2021-07-30T18:10:05.595254+00:00 | 2021-07-30T18:10:05.595306+00:00 | 140 | false | ```\nint maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int n = students.size(), m = students[0].size();\n // n = number of students, m = number of questions\n vector<int> st(n), men(n);\n for(int i = 0; i < n; ++i) {\n int num1 = 0, num2 = 0;... | 1 | 0 | [] | 1 |
maximum-compatibility-score-sum | Simple C++ Sol { Backtracking } | simple-c-sol-backtracking-by-_mrvariable-h7we | \nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int res = INT_MIN, n = students | _MrVariable | NORMAL | 2021-07-28T07:18:58.672991+00:00 | 2021-07-28T07:18:58.673025+00:00 | 97 | false | ```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int res = INT_MIN, n = students.size(), m = students[0].size();\n \n vector<bool> visited(n, false);\n f(0, 0,students, mentors, visited, res, n, m);\n \n ... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | With Bitmasking | with-bitmasking-by-mit1234-yx6n | \nclass Solution {\n int dp[10][1<<10];\npublic:\n int check(vector<vector<int>>&st,vector<vector<int>>&mt,int i,int j)\n {\n int ans=0;\n | mit1234 | NORMAL | 2021-07-27T13:40:21.134893+00:00 | 2021-07-27T13:40:21.134936+00:00 | 52 | false | ```\nclass Solution {\n int dp[10][1<<10];\npublic:\n int check(vector<vector<int>>&st,vector<vector<int>>&mt,int i,int j)\n {\n int ans=0;\n \n for(int k=0;k<st[i].size();k++)\n {\n if(st[i][k]==mt[j][k])\n {\n ans++;\n }\n }\n... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | 3-line Python | 3-line-python-by-maristie-cvqz | An alternative optimization is to decorate function score() with @cache to avoid duplicated computations.\n\npython\n def maxCompatibilitySum(self, students: | maristie | NORMAL | 2021-07-27T06:59:03.616223+00:00 | 2021-07-27T10:20:42.627542+00:00 | 91 | false | An alternative optimization is to decorate function `score()` with `@cache` to avoid duplicated computations.\n\n```python\n def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n def score(s_id: int, m_id: int) -> int:\n return sum(map(lambda x, y: 1^x^y, stud... | 1 | 0 | [] | 0 |
maximum-compatibility-score-sum | (C++) 1947. Maximum Compatibility Score Sum | c-1947-maximum-compatibility-score-sum-b-h758 | \n\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int m = students.size(), n = | qeetcode | NORMAL | 2021-07-26T17:55:30.327109+00:00 | 2021-07-26T17:55:30.327151+00:00 | 124 | false | \n```\nclass Solution {\npublic:\n int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n int m = students.size(), n = students[0].size(); \n vector<vector<int>> score(m, vector<int>(m)); \n for (int i = 0; i < m; ++i) \n for (int j = 0; j < m; ++j) \... | 1 | 1 | ['C'] | 0 |
maximum-compatibility-score-sum | Java - 74 ms - permutation - beats 100% time and 100% memory | java-74-ms-permutation-beats-100-time-an-8946 | \nclass Solution {\n private int max;\n \n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n max = 0;\n permute(stude | cpp_to_java | NORMAL | 2021-07-26T05:11:30.237782+00:00 | 2021-07-26T05:11:59.041979+00:00 | 51 | false | ```\nclass Solution {\n private int max;\n \n public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n max = 0;\n permute(students, mentors, 0, students.length);\n return max;\n }\n \n private void permute(int[][] students, int[][] mentors, int index, int N){\n ... | 1 | 0 | [] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.