You are given an array nums of positive integers and a target. You need to return the length of the longest subsequence whose elements sum exactly to target.
However, you must manage a cooldown mechanic: every time you include an element nums[i] in your subsequence, you are forbidden from including any of the next k elements from the original array in your subsequence, where k = nums[i] % 4.
Find the maximum length of a valid subsequence. If no valid subsequence exists that sums exactly to target, return -1.
Input Format
N, denoting the size of the array.target, denoting the required sum.N space-separated integers denoting the N positive integers nums.Constraints
Infosys • Pending
Infosys • Pending
MotorQ • Pending
MotorQ • Pending
Inmobi • Pending