Check Max-Heap
The first line of input contains an integer, that denotes the value of the size of the array. Let us denote it with the symbol N.
The following line contains N space separated integers, that denote the value of the elements of the array.
The first and only line of output contains true if it represents max-heap and false if it is not a max-heap.
1 <= N <= 10^5
1 <= Ai <= 10^5
Time Limit: 1 sec
8
42 20 18 6 14 11 9 4
true
bool isMaxHeap(int arr[], int n) { // Write your code here for(int i=0;i<n-1;i++){ if(arr[i]<arr[i+1])return false; } return true;}
Comments
Post a Comment