TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 2847,3 "name": "find_maximum_number_of_string_pairs",4 "difficulty": "Easy",5 "link": "https://leetcode.com/problems/find-maximum-number-of-string-pairs/",6 "date": "2023-06-10 00:00:00",7 "task_description": "You are given a **0-indexed** array `words` consisting of **distinct** strings. The string `words[i]` can be paired with the string `words[j]` if: The string `words[i]` is equal to the reversed string of `words[j]`. `0 <= i < j < words.length`. Return _the **maximum** number of pairs that can be formed from the array _`words`_._ Note that each string can belong in **at most one** pair. **Example 1:** ``` **Input:** words = [\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"] **Output:** 2 **Explanation:** In this example, we can form 2 pair of strings in the following way: - We pair the 0th string with the 2nd string, as the reversed string of word[0] is \"dc\" and is equal to words[2]. - We pair the 1st string with the 3rd string, as the reversed string of word[1] is \"ca\" and is equal to words[3]. It can be proven that 2 is the maximum number of pairs that can be formed. ``` **Example 2:** ``` **Input:** words = [\"ab\",\"ba\",\"cc\"] **Output:** 1 **Explanation:** In this example, we can form 1 pair of strings in the following way: - We pair the 0th string with the 1st string, as the reversed string of words[1] is \"ab\" and is equal to words[0]. It can be proven that 1 is the maximum number of pairs that can be formed. ``` **Example 3:** ``` **Input:** words = [\"aa\",\"ab\"] **Output:** 0 **Explanation:** In this example, we are unable to form any pair of strings. ``` **Constraints:** `1 <= words.length <= 50` `words[i].length == 2` `words` consists of distinct strings. `words[i]` contains only lowercase English letters.",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "words = [\"cd\",\"ac\",\"dc\",\"ca\",\"zz\"]",12 "output": "2 "13 },14 {15 "label": "Example 2",16 "input": "words = [\"ab\",\"ba\",\"cc\"]",17 "output": "1 "18 },19 {20 "label": "Example 3",21 "input": "words = [\"aa\",\"ab\"]",22 "output": "0 "23 }24 ],25 "private_test_cases": [26 {27 "input": [28 "\"cd\"",29 "\"sj\"",30 "\"mi\"",31 "\"ne\"",32 "\"hc\"",33 "\"tb\"",34 "\"gq\"",35 "\"mn\"",36 "\"im\"",37 "\"nm\"",38 "\"xr\"",39 "\"ry\"",40 "\"ir\"",41 "\"zw\"",42 "\"yo\"",43 "\"cp\"",44 "\"ou\"",45 "\"yp\"",46 "\"qh\"",47 "\"ru\"",48 "\"sb\"",49 "\"ja\"",50 "\"fz\"",51 "\"le\"",52 "\"da\"",53 "\"ur\"",54 "\"nh\"",55 "\"ap\"",56 "\"gz\"",57 "\"ai\"",58 "\"hv\"",59 "\"rx\"",60 "\"sl\"",61 "\"dg\"",62 "\"lo\"",63 "\"js\"",64 "\"pa\"",65 "\"yz\"",66 "\"bb\"",67 "\"gc\"",68 "\"ol\"",69 "\"im\"",70 "\"en\"",71 "\"uo\"",72 "\"ag\"",73 "\"qg\"",74 "\"zg\"",75 "\"gd\""76 ],77 "output": 1378 },79 {80 "input": [81 "\"nh\"",82 "\"lh\"",83 "\"si\"",84 "\"hn\"",85 "\"zt\"",86 "\"hl\"",87 "\"uq\"",88 "\"ih\"",89 "\"wp\"",90 "\"at\"",91 "\"hi\"",92 "\"vn\"",93 "\"ta\"",94 "\"ow\"",95 "\"rr\"",96 "\"mt\"",97 "\"pi\"",98 "\"qu\""99 ],100 "output": 5101 },102 {103 "input": [104 "\"bs\"",105 "\"mj\"",106 "\"ap\"",107 "\"yo\"",108 "\"wh\"",109 "\"qs\"",110 "\"ei\"",111 "\"lc\"",112 "\"iw\"",113 "\"ew\"",114 "\"cs\"",115 "\"no\"",116 "\"kc\"",117 "\"jx\"",118 "\"sq\"",119 "\"tk\"",120 "\"pi\"",121 "\"xj\"",122 "\"yl\"",123 "\"bj\"",124 "\"wa\"",125 "\"pw\"",126 "\"cl\"",127 "\"hn\"",128 "\"yg\"",129 "\"jm\"",130 "\"nb\"",131 "\"aw\"",132 "\"mw\"",133 "\"wp\"",134 "\"kq\"",135 "\"kt\"",136 "\"qk\"",137 "\"xi\"",138 "\"wm\"",139 "\"lx\""140 ],141 "output": 9142 },143 {144 "input": [145 "\"ks\"",146 "\"ic\"",147 "\"jk\"",148 "\"ww\"",149 "\"mn\"",150 "\"nk\"",151 "\"qn\"",152 "\"sp\"",153 "\"bt\"",154 "\"tf\"",155 "\"zx\"",156 "\"bu\"",157 "\"kn\"",158 "\"oo\"",159 "\"fc\"",160 "\"zg\"",161 "\"ub\"",162 "\"ke\"",163 "\"mg\"",164 "\"nq\"",165 "\"ny\"",166 "\"tf\"",167 "\"ed\"",168 "\"lt\"",169 "\"go\"",170 "\"zi\"",171 "\"xz\"",172 "\"xs\"",173 "\"cg\"",174 "\"wt\"",175 "\"wp\"",176 "\"hw\"",177 "\"pw\"",178 "\"nc\"",179 "\"ft\"",180 "\"ek\"",181 "\"jc\"",182 "\"ux\"",183 "\"cj\"",184 "\"iz\"",185 "\"mr\"",186 "\"tb\"",187 "\"vn\"",188 "\"gc\"",189 "\"jc\"",190 "\"ja\"",191 "\"py\"",192 "\"nm\"",193 "\"dm\"",194 "\"og\""195 ],196 "output": 15197 },198 {199 "input": [200 "\"mm\"",201 "\"di\"",202 "\"cz\"",203 "\"jh\"",204 "\"wr\"",205 "\"pj\"",206 "\"ms\"",207 "\"kh\"",208 "\"ce\"",209 "\"zc\"",210 "\"sm\"",211 "\"ca\"",212 "\"ib\"",213 "\"jp\"",214 "\"rv\"",215 "\"id\""216 ],217 "output": 4218 }219 ],220 "haskell_template": "maximumNumberOfStringPairs :: [String] -> Int\nmaximumNumberOfStringPairs words ",221 "ocaml_template": "let maximumNumberOfStringPairs (words: string list) : int = ",222 "scala_template": "def maximumNumberOfStringPairs(words: List[String]): Int = { \n \n}",223 "java_template": "class Solution {\n public int maximumNumberOfStringPairs(String[] words) {\n \n }\n}",224 "python_template": "class Solution(object):\n def maximumNumberOfStringPairs(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"\n "225}