We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2c29361 commit 9605d21Copy full SHA for 9605d21
Basic/Height of Heap/height-of-heap.cpp
@@ -0,0 +1,40 @@
1
+//{ Driver Code Starts
2
+//Initial template for C++
3
+
4
+#include<bits/stdc++.h>
5
+using namespace std;
6
7
+// } Driver Code Ends
8
+// User function Template for C++
9
10
+class Solution{
11
+public:
12
+ int heapHeight(int N, int arr[]){
13
+ int count=0,i=0;
14
+ while(i<N){
15
+ i=2*i+1;
16
+ count++;
17
+ }
18
+ return count-1;
19
20
+};
21
22
+//{ Driver Code Starts.
23
24
+int main() {
25
+ int t;
26
+ cin>>t;
27
+ while(t--){
28
+ int N;
29
+ cin >> N;
30
+ int arr[N];
31
+ for(int i = 0; i < N; i++)
32
+ cin >> arr[i];
33
34
+ Solution ob;
35
+ cout << ob.heapHeight(N, arr) << endl;
36
37
+ return 0;
38
+}
39
40
0 commit comments