Count of characters in str1 such that after deleting anyone of them str1 becomes str2 | Program to print the given pattern ; Function to return the count of required indices ; Solution doesn 't exist ; Find the length of the longest common prefix of strings ; Find the length of the longest common suffix of strings ; If solution does not exist ; Return the count of indices ; Driver code
using System ; class GFG { static int Find_Index ( String str1 , String str2 ) { int n = str1 . Length ; int m = str2 . Length ; int l = 0 ; int r = 0 ; int i , j ; if ( n != m + 1 ) { return - 1 ; } for ( i = 0 ; i < m ; i ++ ) { if ( str1 [ i ] == str2 [ i ] ) { l += 1 ; } else { break ; } } i = n - 1 ; j = m - 1 ; while ( i >= 0 && j >= 0 && str1 [ i ] == str2 [ j ] ) { r += 1 ; i -= 1 ; j -= 1 ; } if ( l + r < m ) { return - 1 ; } else { i = Math . Max ( n - r , 1 ) ; j = Math . Min ( l + 1 , n ) ; return ( j - i + 1 ) ; } } public static void Main ( String [ ] args ) { String str1 = " aaa " , str2 = " aa " ; Console . WriteLine ( Find_Index ( str1 , str2 ) ) ; } }