Does array represent Heap
Submissions: 10316   Accuracy:

39.27%

  Difficulty: Basic   Marks: 1

Given an array A of size N, the task is to check if the given array represents a Binary Max Heap.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains two lines. The first line of input contains an integer N denoting the size of the array. Then in the next line are N space separated array elements.

Output:
If array represents a Binary Max Heap, print "1", else print "0" (without quotes).

Constraints:
1 <= T <= 100
1 <= N <= 107
1 <= Ai <= 1015

Example:
Input:

2
6
90 15 10 7 12 2
6
9 15 10 7 12 11

Output:
1
0

Explanation:
Testcase 1:
Array of first elements represents Binary Max Heap, so output is 1.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.