i did it till here but i'm not getting further logic how do i proceed further can u…
- User
i did it till here but i'm not getting further logic how do i proceed further can u please hint don't give me any code but help me think through the solution the question constructing the binary tree from post order and inorder traversal class Solution { public: int findIndex(vector inorder, int ele){ for(int i=0;i<inorder.size();i++){ if(inorder[i] == ele){ return i; } } } void solve(int root, vector inorder, vector postorder){ root->right=solve(root, ) }
code// Function to return a tree created from postorder and inoreder traversals. Node* buildTree(vector<int> inorder, vector<int> postorder) { // code here Node* root; root->data=postorder[postorder.size()-1]; solve(root,inorder, postorder); }};
- Assistant
You're on the right track by considering how to construct a binary tree using postorder and inorder traversal data. Here’s a hint to help you think through the solution without giving you the full code.
- User
but i have already written this code how do i modify it class Solution { public: int findIndex(vector inorder, int ele){ for(int i=0;i<inorder.size();i++){ if(inorder[i] == ele){ return i; } } } void solve(int root, vector inorder, vector postorder){ root->right=solve(root, ) }
code// Function to return a tree created from postorder and inoreder traversals. Node* buildTree(vector<int> inorder, vector<int> postorder) { // code here Node* root; root->data=postorder[postorder.size()-1]; solve(root,inorder, postorder); }};
- Assistant
- User
but do not give me any code just give me some hints based on the code provided below so that i can create it on my own class Solution { public: int findIndex(vector inorder, int ele){ for(int i=0;i<inorder.size();i++){ if(inorder[i] == ele){ return i; } } } void solve(int root, vector inorder, vector postorder){ root->right=solve(root, ) }
code// Function to return a tree created from postorder and inoreder traversals. Node* buildTree(vector<int> inorder, vector<int> postorder) { // code here Node* root; root->data=postorder[postorder.size()-1]; solve(root,inorder, postorder); }};
- Assistant
Certainly! Here are some hints to help you progress with the code you provided without revealing any specific code.
- User
how do i construct the binary tree from scratch
- Assistant