Space efficient Java program to count all substrings with same first and last characters .
public class GFG { static int countSubstringWithEqualEnds ( String s ) { int result = 0 ; int n = s . length ( ) ;