Check if edit distance between two strings is one | C # program to check if given two strings are at distance one . ; Returns true if edit distance between s1 and s2 is one , else false ; Find lengths of given strings ; If difference between lengths is more than 1 , then strings can 't  be at one distance ; Count of edits ; If current characters don 't match ; If length of one string is more , then only possible edit is to remove a character ; If lengths of both strings is same ; Increment count of edits ; If current characters match ; If last character is extra in any string ; Driver code
using System ; class GFG { static bool isEditDistanceOne ( String s1 , String s2 ) { int m = s1 . Length , n = s2 . Length ; if ( Math . Abs ( m - n ) > 1 ) return false ; int count = 0 ; int i = 0 , j = 0 ; while ( i < m && j < n ) { if ( s1 [ i ] != s2 [ j ] ) { if ( count == 1 ) return false ; if ( m > n ) i ++ ; else if ( m < n ) j ++ ; else { i ++ ; j ++ ; } count ++ ; } else { i ++ ; j ++ ; } } if ( i < m < n ) count ++ ; return count == 1 ; } public static void Main ( ) { String s1 = " gfg " ; String s2 = " gf " ; if ( isEditDistanceOne ( s1 , s2 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }