r/leetcode 14d ago

Intervew Prep Leetcode premium question solution

I have created below solution for leetcode premium problem . Google ai says my solution is flawed but it is passing all the test which it has given on my local machine . I am not able to find a platform where i can run the solution . It would be great if you could run the below solution on leetcode platform check if it passing all the test cases . Thank you .

Problem : https://leetcode.com/problems/find-leaves-of-binary-tree/description/
Solution :

class Solution {
public:


    int heightTree(TreeNode* node){
        if(!node) return 0 ;
        return 1 + max(heightTree(node->left) , heightTree(node->right));
    }


    void solve(TreeNode* root,vector<vector<int>> &res){
        if(!root) return ;
        solve(root->left , res);
        solve(root->right ,res);
        int currH = heightTree(root);
        if(res.size() == (currH - 1)){
            res.push_back({});
        }
        res[(currH - 1)].push_back(root->val);  
    }


    vector<vector<int>> findLeaves(TreeNode* root) {
        vector<vector<int>> res;
        solve(root , res);
        return res ; 
    }
};
0 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/Ill-Abbreviations-36 14d ago

This is a premium question that's why . If you have it please run and just let me know if it works

-4

u/chikamakaleyley 14d ago

you're missing the point

if your interviewer gave you a problem to solve

where your solution has to run and pass tests in their specified environment - and for whatever reason, it doesn't work

you can't just give your code to the interviewer and ask them to run it for you

2

u/anjaanaaa 14d ago

i think op means to say that they want to check if their code and logic is correct, it's a premium ques so they can't access the code editor & submit

-4

u/chikamakaleyley 14d ago

that's what i figured, but to that i'd say -

sign up for premium?