I wrote this code on geeks fir geeks this code’s time complexity is o(n)?
Why this error is in being shown.
ERROR: Abort signal from abort(3) (SIGABRT)
Problem link:-
https://practice.geeksforgeeks.org/problems/bottom-view-of-binary-tree/1
submitted code:-
Node** printBottomView(Node* root,int n,Node arr[])
{
// static Node arr[1000]={0};
if(root==nullptr)
{
return arr;
}
else
{
arr[n]=root;
printBottomView(root->left,n-1,arr);
printBottomView(root->right,n+1,arr);
return arr;
}
}
int findNoOfNodes(Node* root,int *n)
{
// static int n=0;
if(root)
{
n+=1;
// cout<< n<<" ";
findNoOfNodes(root->left,n);
findNoOfNodes(root->right,n);
return n;
}
return 0;
}
// Method that prints the bottom view.
void bottomView(Node root)
{
// Your Code Here//
int n=0;
findNoOfNodes(root,&n);
// cout<<n<<endl;
Node arr=new Node[1000000];
printBottomView(root,n,arr);
for(int i=0;i<=2n;i++)
{
if(arr[i])
{
cout<<arr[i]->data<<" ";
}
}
delete *arr;
}