Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created May 5, 2018 05:19
Show Gist options
  • Save sreeprasad/f694ec8e58b88eb5a2dcfeac791cf3f3 to your computer and use it in GitHub Desktop.
Save sreeprasad/f694ec8e58b88eb5a2dcfeac791cf3f3 to your computer and use it in GitHub Desktop.
pivot
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N,count=0;
scanf(" %d",&N);
int* array = new int[N];
int* min_array = new int[N];
int* max_array = new int[N];
scanf(" %d",&array[0]);
max_array[0] = array[0];
int max = array[0] ;
for(int i=1;i<N;i++){
scanf(" %d",&array[i]);
if(array[i]>max){
max = array[i];
}
max_array[i] = max;
}
min_array[N-1] = array[N-1];
int min = array[N-1] ;
for(int i=N-2;i>=0;i--){
if(array[i]<min){
min = array[i];
}
min_array[i] = min;
}
for(int i=0;i<N;i++){
if(max_array[i]<=array[i] && array[i]<=min_array[i]){
count++;
}
}
printf("%d",count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment