Simple python3 solution | Dynamic Programming + Hash Table
Complexity\n- Time complexity: O(n^2 \cdot \log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.
# Complexity\n- Time complexity: $$O(n^2 \\cdot \\log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n        dp = {0: 0}\n\n        for elem in nums:\n            for k in sorted(dp, reverse=True):\n                if k + elem <= target:\n                    dp[k + elem] = max(\n                        dp.get(k + elem, 0),\n                        dp[k] + 1,\n                    )\n        \n        return dp.get(target, -1)\n```
['Hash Table', 'Dynamic Programming', 'Sorting', 'Python3']