C++ Easiest Solution || Beast 100%
Intuition\n For each pair of characters with the same value, it calculates the length of the substring between them (excluding the two characters) and updates t
# Intuition\n For each pair of characters with the same value, it calculates the length of the substring between them (excluding the two characters) and updates the maximum length if the calculated length is greater than the current maximum.\n\n# Approach\n1. Nested Loop : You iterate over each pair of characters in the string using two nested loops.\n\n1. Check for Equality: Within the nested loops, you check if the characters at positions i and j are equal.\n\n1. Calculate Substring Length: If the characters are equal, you calculate the length of the substring between them (excluding the two characters) by subtracting the starting index (i+1) from the ending index (j).\n\n1. Update Maximum Length: If the calculated length is greater than the current maximum length (max), you update the maximum length.\n\n1. Return Maximum Length: After the nested loops, the function returns the maximum length.\n\n# Complexity\n- Time complexity:  O(n^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n![Screenshot (125).png](https://assets.leetcode.com/users/images/1377e5ee-db42-469d-a7aa-b85f69173f68_1703994971.2189271.png)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxLengthBetweenEqualCharacters(string s) {\n        int n=s.size();\n        int x,max=-1;\n        for(int i=0;i<n;i++)\n        {\n           for(int j=n-1;j>i;j--)\n           {\n                  if(s[i]==s[j])\n                  {\n                      x=j-(i+1);\n                         if(x>max)\n                         {\n                             max=x;\n                         }\n                  }\n           }\n        }\n        return max;\n    }\n};\n```
['C', 'C++']