Count Maximum Reversed String Pairs in an Array
IntuitionTo solve this problem, the main idea is to identify pairs of strings where one is the reverse of the other. Since the words array consists of distinct
# Intuition

To solve this problem, the main idea is to identify pairs of strings where one is the reverse of the other. Since the `words` array consists of distinct strings, we can safely check all possible pairs without worrying about duplicates. 

The most intuitive approach is to use two nested loops:
1. Fix one string (`words[i]`) and iterate through the rest (`words[j]`) to find a match.
2. Reverse `words[j]` and compare it with `words[i]`. If they match, it means we have found a valid pair.
3. Count such pairs and ensure each string belongs to at most one pair.

This approach is straightforward and ensures we cover all possibilities systematically.

# Approach

1. **Initialize a Counter**: Start with a `count` variable set to `0`. This will keep track of the number of valid pairs found.

2. **Iterate Through the Array**:
   - Use a nested loop where the outer loop iterates through each string (`words[i]`), and the inner loop iterates through all subsequent strings (`words[j]`).

3. **Check for Reverse Match**:
   - For each pair of strings (`words[i]`, `words[j]`), reverse the second string (`words[j]`) using `.split('').reverse().join('')`.
   - Compare the reversed string with the first string (`words[i]`). If they are equal, it means we have found a valid pair.

4. **Update the Counter**:
   - If a valid pair is found, increment the `count`.

5. **Return the Result**:
   - After checking all possible pairs, return the value of `count` as the final result.

This approach ensures that all pairs are checked while maintaining clarity and simplicity. Since each string can belong to only one pair, there is no risk of overcounting.

# Complexity

- **Time Complexity**:  
  The algorithm uses a nested loop to compare each string with all subsequent strings in the array.  
  - Outer loop runs for $$n$$ iterations (where $$n$$ is the length of the array).  
  - Inner loop runs for $$n-1$$, $$n-2$$, ..., 1 iterations for each pass of the outer loop.  
  Therefore, the total number of comparisons is:
  $$\text{Total comparisons} = 1 + 2 + 3 + ... + (n-1) = \frac{n(n-1)}{2}$$  
  Hence, the time complexity is $$O(n^2)$$.

- **Space Complexity**:  
  - Reversing a string (`words[j].split('').reverse().join('')`) takes $$O(k)$$ space, where $$k$$ is the length of the string (constant in this problem as the length of each word is 2).  
  - Apart from this, no extra space is used, as the operations are done in-place.  
  Therefore, the space complexity is $$O(1)$$.

# Code
```javascript []
/**
 * @param {string[]} words
 * @return {number}
 */
var maximumNumberOfStringPairs = function(words) {
    let count = 0;

    for (let i = 0; i < words.length; i++) {
        for (let j = i + 1; j < words.length; j++) {

            if (words[i] === words[j].split('').reverse().join('')) {
                count++;
            }
        }
    }

    return count;
};
```
['JavaScript']