About n and m values when different

what we have to do when value of n and m are different in this question

hi @devashishbotre95_45ed0bc0d0c42ff0 cant be different else tree wont be possible, no such cases will be given

what is wrong in my code, sir

hi @devashishbotre95_45ed0bc0d0c42ff0 send the code

#include #include using namespace std; class node { public: int data; nodeleft; noderight; node(int d) { data=d; left=NULL; right=NULL; } }; node* build(int pre,int in,int s,int e) { static int i=0; if(s>e) { return NULL; } noderoot=new node(pre[i]); int index=-1; for(int j=s;s<=e;j++) { if(in[j]==pre[i]) { index=j; break; } } i++; root->left=build(in,pre,s,index-1); root->right=build(in,pre,index+1,e); return root; } void printpre(noderoot) { if(root==NULL) { return; } if(root->left==NULL) { cout<<β€œEND”; } else { cout<left->data; } cout<<" => β€œ<data<<” <= "; if(root->right==NULL) { cout<<β€œEND”<<endl;; } else { cout<right->data<<endl;; } printpre(root->left); printpre(root->right); return; } int main() { int n,m; cin>>n; int pre[n]; for(int i=0;i<n;i++) { cin>>pre[i]; } cin>>m; int in[m]; for(int i=0;i<m;i++) { cin>>in[i]; } node*root=build(pre,in,0,n-1); printpre(root); return 0; }

hi @devashishbotre95_45ed0bc0d0c42ff0 please send on ide.codingblocks.com
the code is not readable here

  1. login
  2. write
  3. save
  4. send the url of page

hi @devashishbotre95_45ed0bc0d0c42ff0,
for(int j=s;j<=e;j++) // here j<=e not s<=e

sir, code is not working again

hi @devashishbotre95_45ed0bc0d0c42ff0 i checked it please try again its passing all test case