https://github.com/emilwijayasekara/leetcode-2744-find-maximum-number-of-string-pairs
LeetCode Problem 2744. Find Maximum Number of String Pairs - The task is to find the maximum number of pairs that can be formed by pairing distinct strings in an array with their reversed counterparts. Each string can only be part of one pair.
https://github.com/emilwijayasekara/leetcode-2744-find-maximum-number-of-string-pairs
java leetcode leetcode-java leetcode-solutions
Last synced: about 22 hours ago
JSON representation
LeetCode Problem 2744. Find Maximum Number of String Pairs - The task is to find the maximum number of pairs that can be formed by pairing distinct strings in an array with their reversed counterparts. Each string can only be part of one pair.
- Host: GitHub
- URL: https://github.com/emilwijayasekara/leetcode-2744-find-maximum-number-of-string-pairs
- Owner: EmilWijayasekara
- Created: 2024-01-01T16:14:24.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-01T16:25:03.000Z (almost 2 years ago)
- Last Synced: 2025-08-19T08:48:50.652Z (about 2 months ago)
- Topics: java, leetcode, leetcode-java, leetcode-solutions
- Language: Java
- Homepage: https://leetcode.com/problems/find-maximum-number-of-string-pairs/description/
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LeetCode Practice (Day 14)
## Achievements
[](https://postimg.cc/zVVW8RFm)
## About the problem
- *Problem Number* : 2744
- *Problem Name* : [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs/description/ "https://leetcode.com/problems/find-maximum-number-of-string-pairs/description/")
- *Problem difficulty* : Easy (88.47%)🟢
- *Programming language used* - Java## Problem
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.## Approach Explanation
I examined all possible pairs, checking if each pair met the specified conditions of reversibility. Specifically, I compared the first character of one string with the second character of another and vice versa. The resulting count represents the maximum number of valid pairs that can be formed from the array. While this approach provides a correct solution, it relies on a brute-force method, potentially leading to inefficiencies for larger input sizes.### If you have suggestions for improvement or would like to contribute to this solution, feel free to create a pull request. 🙌😇