Python Super Easy Solution w/e for Beginners.
Intuition\nLongest subsequence comes by including more number of elements into it, and also the sum should be <= query[i]. So we have to include elements in inc
# Intuition\nLongest subsequence comes by including more number of elements into it, and also the sum should be <= query[i]. So we have to include elements in increasing order. Then we can include more number of elements.\n\nEx: Consider nums=[10,2,3,5] and query=[10]\nfirst element of query is 10.\nif we include nums[0], the length will be 1 and we cannot include more elements as the sum will cross query[i].\n\n# Approach\nHence lets sort the nums.\nafter sorting:\nnums=[2,3,5,10]\nNow loop on nums for every query and find whether the element can be added to the subsequence or not. so check that sum + nums[i] <= query[i] or not. If the condition is True, add the element to sum and increment length by 1. If the condition is False, stop the loop and that will be the longest subsequence with sum<=query[i].\n\n\n\n# Code\n```\nclass Solution:\n    def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:\n        ans=[]\n        nums.sort()\n        for q in queries:\n            s=0 #sum of subsequence\n            l=0 #length of subsequence\n            for i in nums:\n                if s+i<=q: #check before adding the element.\n                    s=s+i\n                    l=l+1\n                else:\n                    break\n            ans.append(l)\n        return ans\n```
['Python3']