Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2744 - Find Maximum Number of String Pairs\.

    Easy

    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 0<sup>th</sup> string with the 2<sup>nd</sup> string, as the reversed string of word0 is "dc" and is equal to words2.

    • We pair the 1<sup>st</sup> string with the 3<sup>rd</sup> string, as the reversed string of word1 is "ca" and is equal to words3.

    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 0<sup>th</sup> string with the 1<sup>st</sup> string, as the reversed string of words1 is "ab" and is equal to words0.

    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 &lt;= words.length &lt;= 50

    • words[i].length == 2

    • words consists of distinct strings.

    • words[i] contains only lowercase English letters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maximumNumberOfStringPairs(Array<String> words)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait