Grouping Countries | C # program to count no . of distinct countries from a given group of people ; Answer is valid if adjacent sitting num people give same answer ; someone gives different answer ; check next person ; one valid country group has been found ; Driver Code
using System ; class Country { public static void countCountries ( int [ ] ans , int N ) { int total_countries = 0 , i = 0 ; while ( i < N ) { int curr_size = ans [ i ] ; int num = ans [ i ] ; while ( num > 0 ) { if ( ans [ i ] != curr_size ) { Console . Write ( " Invalid ▁ Answer STRNEWLINE " ) ; return ; } else num -- ; i ++ ; } total_countries ++ ; } Console . Write ( " There ▁ are ▁ " + total_countries + " ▁ distinct ▁ companies ▁ in ▁ the ▁ group . STRNEWLINE " ) ; } public static void Main ( ) { int [ ] ans = { 1 , 1 , 2 , 2 , 4 , 4 , 4 , 4 } ; int n = 8 ; countCountries ( ans , n ) ; } }