2744. Find Maximum Number of String Pairs Easy

@problem@discussion
#Array#Hash Table#String#Simulation



1/**
2 * [2744] Find Maximum Number of String Pairs
3 *
4 * You are given a 0-indexed array words consisting of distinct strings.
5 * The string words[i] can be paired with the string words[j] if:
6 * 
7 * 	The string words[i] is equal to the reversed string of words[j].
8 * 	0 <= i < j < words.length.
9 * 
10 * Return the maximum number of pairs that can be formed from the array words.
11 * Note that each string can belong in at most one pair.
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: words = ["cd","ac","dc","ca","zz"]
16 * Output: 2
17 * Explanation: In this example, we can form 2 pair of strings in the following way:
18 * - We pair the 0^th string with the 2^nd string, as the reversed string of word[0] is "dc" and is equal to words[2].
19 * - We pair the 1^st string with the 3^rd string, as the reversed string of word[1] is "ca" and is equal to words[3].
20 * It can be proven that 2 is the maximum number of pairs that can be formed.
21 * <strong class="example">Example 2:
22 * 
23 * Input: words = ["ab","ba","cc"]
24 * Output: 1
25 * Explanation: In this example, we can form 1 pair of strings in the following way:
26 * - We pair the 0^th string with the 1^st string, as the reversed string of words[1] is "ab" and is equal to words[0].
27 * It can be proven that 1 is the maximum number of pairs that can be formed.
28 * 
29 * <strong class="example">Example 3:
30 * 
31 * Input: words = ["aa","ab"]
32 * Output: 0
33 * Explanation: In this example, we are unable to form any pair of strings.
34 * 
35 *  
36 * Constraints:
37 * 
38 * 	1 <= words.length <= 50
39 * 	words[i].length == 2
40 * 	words consists of distinct strings.
41 * 	words[i] contains only lowercase English letters.
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/find-maximum-number-of-string-pairs/
47// discuss: https://leetcode.com/problems/find-maximum-number-of-string-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn maximum_number_of_string_pairs(words: Vec<String>) -> i32 {
53        0
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_2744() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.