Count characters of a string which when removed individually makes the string equal to another string | C # program for the above approach ; Function to count characters from string A whose removal makes the strings A and B equal ; Stores the index of the longest prefix ; Stores the index of the longest suffix ; Traverse the string B ; Traverse the string B ; If N - M is equal to 1 and Y is less than or equal to X ; Print the count of characters ; Print the positions of the characters ; Otherwise ; Driver Code
using System ; public class GFG { static void RemoveOneChar ( string A , string B , int N , int M ) { int X = 0 ; int Y = N - 1 ; for ( int i = 0 ; i < M ; i ++ ) { if ( A [ X ] != B [ i ] ) break ; X ++ ; } for ( int i = M - 1 ; i >= 0 ; i -- ) { if ( A [ Y ] != B [ i ] ) break ; Y -- ; } if ( N - M == 1 && Y < X ) { Console . WriteLine ( X - Y + 1 ) ; for ( int i = Y ; i <= X ; i ++ ) Console . Write ( i + 1 + " ▁ " ) ; Console . WriteLine ( ) ; } else Console . WriteLine ( - 1 ) ; } static public void Main ( ) { string A = " abaac " ; string B = " abac " ; int N = A . Length ; int M = B . Length ; RemoveOneChar ( A , B , N , M ) ; } }