Number of buildings facing the sun | C # program to count buildings that can see sunlight . ; 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 method
using System ; class GFG { static int countBuildings ( int [ ] arr , int n ) { int count = 1 ; int curr_max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > curr_max arr [ i ] == curr_max ) { count ++ ; curr_max = arr [ i ] ; } } return count ; } public static void Main ( ) { int [ ] arr = { 7 , 4 , 8 , 2 , 9 } ; Console . Write ( countBuildings ( arr , arr . Length ) ) ; } }