Practice Length of the Longest Subsequence That Sums to Target
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Length of the Longest Subsequence That Sums to Target
Problem Statement
You are given a 0-indexed array of integers nums, and an integer target. Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1. A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
Source: Length of the Longest Subsequence That Sums to Target on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3,4,5], target = 9
3
# Example 2
nums = [4,1,3,2,1,5], target = 7
4
# Example 3
nums = [1,1,5,4,5], target = 3
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Length of the Longest Subsequence That Sums to Target.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.