Discussion on Approach - Can we do this with level order traversal ?
Hey,\n\nI was working on this solution. my approach was to solve this with level order traversal. However it seems to be not possible with that approch. but i w
Hey,\n\nI was working on this solution. my approach was to solve this with level order traversal. However it seems to be not possible with that approch. but i would like to hear/thoughts/suggestions from you all. \n\nmy approch was:\n1. Traverse the tree level wise.\n2. Put values into 1 D (sum of particular level) array now problem reduced to find maximum sum by skipping alternate values. \n\nChallange : How it\'s possibe to implement a solution which involves kth level value + some nth level value in solution.\n\nLooking forward to some amazing answers on this. Thanks \n\nIn case you want my solution (Not passed) \n```\nclass Solution {\npublic:\n    int rob(TreeNode* root) {\n        vector<int> vect;\n        queue<TreeNode*> q;\n        if(root==NULL) return 0;\n        q.push(root);\n        while(q.size()>0){\n            int n = q.size();\n            vector<int> t;\n            for(int i=0;i<n;i++){\n                TreeNode* temp = q.front();\n                q.pop();\n                t.push_back(temp->val);\n                if(temp->left) q.push(temp->left);\n                if(temp->right) q.push(temp->right);\n            }\n            int temp = 0;\n            for(auto item : t) temp+=item;\n            vect.push_back(temp);\n            temp = 0;\n        }\n        int odd = 0 , even =0 , finalAns = vect[0];\n        for(int i=0;i<vect.size();i++){\n            for(int k=i+2;k<vect.size();k+=2){\n                odd += vect[k];\n            }\n            for(int k=i+3;k<vect.size();k+=2){\n                even = vect[k];\n            }\n            if(odd+vect[i] >finalAns){\n                finalAns = odd+vect[i];\n            }\n            if(even+vect[i] > finalAns){\n                finalAns = even+vect[i];\n            }\n            odd = 0;\n            even = 0;\n        }\n        return finalAns;\n    }\n};\n```
['Breadth-First Search', 'Recursion', 'C', 'Iterator', 'C++']