human
Grouping Countries | Python3 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.
Driven code"
Solution in Python:
assistant
#Here is code to grouping Countries and the other steps required.
 def countCountries ( ans , N ) :
	total_countries = 0
	i = 0
	invalid = 0
	while ( i < N ) :
		curr_size = ans [ i ]
		num = ans [ i ]
		while ( num > 0 ) :
			if ( ans [ i ] != curr_size ) :
				print ( " Invalid ▁ Answer " )
				return ;
			else :
				num = num - 1
			i = i + 1
		total_countries = total_countries + 1 ;
	print ( " There ▁ are ▁ " , total_countries , " ▁ distinct ▁ companies ▁ in ▁ the ▁ group . " )
ans = [ 1 , 1 , 2 , 2 , 4 , 4 , 4 , 4 ] ;
n = len ( ans ) ;
countCountries ( ans , n ) ;