Count of ordered triplets ( R , G , B ) in a given original string | C # code for the above program ; function to count the ordered triplets ( R , G , B ) ; count the B ( blue ) colour ; Driver Code
using System ; class GFG { static int countTriplets ( String color ) { int result = 0 , Blue_Count = 0 ; int Red_Count = 0 ; int len = color . Length ; int i ; for ( i = 0 ; i < len ; i ++ ) { if ( color [ i ] == ' B ' ) Blue_Count ++ ; } for ( i = 0 ; i < len ; i ++ ) { if ( color [ i ] == ' B ' ) Blue_Count -- ; if ( color [ i ] == ' R ' ) Red_Count ++ ; if ( color [ i ] == ' G ' ) result += Red_Count * Blue_Count ; } return result ; } public static void Main ( string [ ] args ) { string color = " RRGGBBRGGBB " ; Console . WriteLine ( countTriplets ( color ) ) ; } }