human
Number of buildings facing the sun | Returns count buildings that can see sunlight.
Initialuze result ( Note that first building always sees sunlight ).
Start traversing element.
If curr_element is maximum or current element is equal , update maximum and increment count.
Driver code"
Solution in Python:
assistant
#Here is code to number of buildings facing the sun and the other steps required.
 def countBuildings ( arr , n ) :
	count = 1
	curr_max = arr [ 0 ]
	for i in range ( 1 , n ) :
		if ( arr [ i ] > curr_max or arr [ i ] == curr_max ) :
			count += 1
			curr_max = arr [ i ]
	return count
arr = [ 7 , 4 , 8 , 2 , 9 ]
n = len ( arr )
print ( countBuildings ( arr , n ) )