← 返回 bytedance 的题目列表Hard dynamic programming problem
类型:online_judge
Design and implement a dynamic programming algorithm to satisfy the following requirement: Given an integer array nums and a target sum target, find the maximum length of a contiguous subarray that sums to target.
Input: An integer array nums and an integer target.
Output: The length of the longest contiguous subarray that sums to target.
Examples:
Input: nums = [1, -1, 5, -2, 3], target = 3
Output: 4 (subarray [1, -1, 5, -2] sums to 3)
Input: nums = [-2, -1, 2, 1], target = 1
Output: 2 (subarray [-1, 2] sums to 1)
Data Scale Constraints
The length of array nums is at most 1000.
The absolute value of elements in nums does not exceed 1000.
The absolute value of target does not exceed 10000.
Example
Input
{'nums': [1, -1, 5, -2, 3], 'target': 3}