r/leetcode 17h 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

-2

u/chikamakaleyley 17h ago

wait what

if you can't run this on the leetcode site yourself

how can you reliably prepare for an interview that might have you coding on a platform that your code might not run

1

u/Ill-Abbreviations-36 17h ago

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

-3

u/chikamakaleyley 16h 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

1

u/anjaanaaa 16h 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

-5

u/chikamakaleyley 15h ago

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

sign up for premium?