Concatenated string with uncommon characters of two strings | C # program Find concatenated string with uncommon characters of given strings ; Result ; creating a hashMap to add characters in string s2 ; Find characters of s1 that are not present in s2 and append to result ; Find characters of s2 that are not present in s1 . ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static String concatenatedString ( String s1 , String s2 ) { String res = " " ; int i ; Dictionary < char , int > m = new Dictionary < char , int > ( ) ; for ( i = 0 ; i < s2 . Length ; i ++ ) if ( ! m . ContainsKey ( s2 [ i ] ) ) m . Add ( s2 [ i ] , 1 ) ; for ( i = 0 ; i < s1 . Length ; i ++ ) if ( ! m . ContainsKey ( s1 [ i ] ) ) res += s1 [ i ] ; else m [ s1 [ i ] ] = 2 ; for ( i = 0 ; i < s2 . Length ; i ++ ) if ( m [ s2 [ i ] ] == 1 ) res += s2 [ i ] ; return res ; } public static void Main ( String [ ] args ) { String s1 = " abcs " ; String s2 = " cxzca " ; Console . WriteLine ( concatenatedString ( s1 , s2 ) ) ; } }