Check whether two strings contain same characters in same order | C # implementation of the approach ; String class has a constructor that allows us to specify size of String as first parameter and character to be filled in given size as second parameter . ; Function that returns true if the given Strings contain same characters in same order ; Get the first character of both Strings ; Now if there are adjacent similar character remove that character from s1 ; Now if there are adjacent similar character remove that character from s2 ; If both the strings are equal then return true ; Driver code
using System ; public class temp { static String getString ( char x ) { String s = String . Join ( " " , x ) ; return s ; } static Boolean solve ( String s1 , String s2 ) { String a = getString ( s1 [ 0 ] ) , b = getString ( s2 [ 0 ] ) ; for ( int i = 1 ; i < s1 . Length ; i ++ ) if ( s1 [ i ] != s1 [ i - 1 ] ) { a += getString ( s1 [ i ] ) ; } for ( int i = 1 ; i < s2 . Length ; i ++ ) if ( s2 [ i ] != s2 [ i - 1 ] ) { b += getString ( s2 [ i ] ) ; } if ( a == b ) return true ; return false ; } public static void Main ( String [ ] args ) { String s1 = " Geeks " , s2 = " Geks " ; if ( solve ( s1 , s2 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }