Buildings
Problem Statement
There are N buildings in a row with different heights H[i] (1 <= i <= N).
You are viewing the buildings from the left and you can see the roof of a building i if no building to the left of the ith building has a height greater than the ith building.
You are asked to find the number of buildings whose roofs you can see.
You are viewing the buildings from the left and you can see the roof of a building i if no building to the left of the ith building has a height greater than the ith building.
You are asked to find the number of buildings whose roofs you can see.
import java.io.*;
import java.util.*;
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int buld=sc.nextInt();
int a[]=new int[buld];
for(int i=0;i<buld;i++){
a[i]=sc.nextInt();
}
int count=1;
int max=a[0];
for(int i=1;i<buld;i++){
if(max<a[i]){
++count;
max=a[i];
}
}
System.out.print(count);
}
}