Check if a string is the typed name of the given name | Check if the character is vowel or not ; Returns true if ' typed ' is a typed name given str ; Traverse through all characters of str . ; If current characters do not match ; If not vowel , simply move ahead in both ; Count occurrences of current vowel in str ; Count occurrences of current vowel in typed . ; Driver code
< ? php function isVowel ( $ c ) { $ vowel = " aeiou " ; for ( $ i = 0 ; $ i < strlen ( $ vowel ) ; ++ $ i ) if ( $ vowel [ $ i ] == $ c ) return true ; return false ; } function printRLE ( $ str , $ typed ) { $ n = strlen ( $ str ) ; $ m = strlen ( $ typed ) ; $ j = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ str [ $ i ] != $ typed [ $ j ] ) return false ; if ( isVowel ( $ str [ $ i ] ) == false ) { $ j ++ ; continue ; } $ count1 = 1 ; while ( $ i < $ n - 1 && $ str [ $ i ] == $ str [ $ i + 1 ] ) { $ count1 ++ ; $ i ++ ; } $ count2 = 1 ; while ( $ j < $ m - 1 && $ typed [ $ j ] == $ str [ $ i ] ) { $ count2 ++ ; $ j ++ ; } if ( $ count1 > $ count2 ) return false ; } return true ; } $ name = " alex " ; $ typed = " aaalaeex " ; if ( printRLE ( $ name , $ typed ) ) echo " Yes " ; else echo " No " ; ? >