Count of ' GFG ' Subsequences in the given string | Javascript Program to find the " GFG " subsequence in the given string ; Print the count of " GFG " subsequence in the string ; Traversing the given string ; If the character is ' G ' , increment the count of ' G ' , increase the result and update the array . ; If the character is ' F ' , increment the count of ' F ' and update the array . ; Ignore other character . ; Driven Program
var MAX = 100 ; function countSubsequence ( s , n ) { var cntG = 0 , cntF = 0 , result = 0 , C = 0 ; for ( var i = 0 ; i < n ; i ++ ) { switch ( s [ i ] ) { case ' ' : cntG ++ ; result += C ; break ; case ' ' : cntF ++ ; C += cntG ; break ; default : continue ; } } document . write ( result ) ; } var s = " " ; var n = ( s . length ) ; countSubsequence ( s , n ) ;