✔️Python, C++,Java|| Beginner level||Simple-Short-Solution✔️
Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome.\n___\n__\nQ
***Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome*.**\n___________________\n_________________\n***Q2389. Longest Subsequence With Limited Sum***\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\n\u2705 **Python  Code** :\n```\nclass Solution:\n    def findSolution(self, customfunction: \'CustomFunction\', z: int) -> List[List[int]]:\n        res=[]\n        x,y=1,1000\n        while x<1000 and y>0:\n            if customfunction.f(x,y)==z:\n                res.append([x,y])\n                x+=1\n                y-=1\n            elif customfunction.f(x,y)>z:\n                y-=1\n            else:\n                x+=1\n        return res\n```\n**Runtime:**  943 ms\t\n**Memory Usage:**  13.6 MB\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\n\n\u2705 **Java Code** :\n```\nclass Solution {\n    public int[] answerQueries(int[] nums, int[] queries) {\n       Arrays.sort(nums);\n    for(int i = 0; i < queries.length; i++) {\n        int curr = 0;\n        int count = 0;\n        for(int j = 0; j < nums.length; j++) {\n            curr += nums[j];\n            if(curr <= queries[i]) {\n                count++;\n            }\n            else \n                curr -= nums[j];\n        }\n        queries[i] = count;\n    }\n    return queries; \n    }\n}\n```\n**Runtime:**  39 ms\t\t\n**Memory Usage:**  48 MB\t\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\n\u2705 **C++  Code** :\n```\nclass Solution {\npublic:\n   \n    vector<int> answerQueries(vector<int>& nums, vector<int>& queries) {\n        int n = queries.size();\n        sort(nums.begin(), nums.end());\n        for(int i = 1; i < nums.size(); i++)\n            nums[i] += nums[i - 1];\n        vector<int> res(n);\n        for(int i = 0; i < n; i++){\n            int idx = upper_bound(nums.begin(), nums.end(), queries[i]) - nums.begin();\n            res[i] = idx;\n        }\n        return res;\n    }\n};\n```\n**Runtime:** 17 ms\t\n**Memory Usage:**  13 MB\t\t\n____________________________________________________________________________________________________________________\n____________________________________________________________________________________________________________________\nIf you like the solution, please upvote \uD83D\uDD3C\nFor any questions, or discussions, comment below. \uD83D\uDC47\uFE0F\n
['C', 'Sorting', 'Binary Tree', 'Python', 'Java']