Least number of manipulations needed to ensure two strings have identical characters | C # program to count least number of manipulations to have two strings set of same characters ; return the count of manipulations required ; count the number of different characters in both strings ; check the difference in characters by comparing count arrays ; driver program
using System ; public class GFG { static int MAX_CHAR = 26 ; static int leastCount ( string s1 , string s2 , int n ) { int [ ] count1 = new int [ MAX_CHAR ] ; int [ ] count2 = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { count1 [ s1 [ i ] - ' a ' ] += 1 ; count2 [ s2 [ i ] - ' a ' ] += 1 ; } int res = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( count1 [ i ] != 0 ) { res += Math . Abs ( count1 [ i ] - count2 [ i ] ) ; } } return res ; } static public void Main ( ) { string s1 = " abc " ; string s2 = " cdd " ; int len = s1 . Length ; int res = leastCount ( s1 , s2 , len ) ; Console . WriteLine ( res ) ; } }