Cisco OA-5 2022
Problem Description
Find the maximum number of elements in a given array that sum up to a given target.
Input:
- The first line specifies the number of elements in the array
- The second line specifies the target.
- The third lines contain the elements of the array (Integers).
Output:
Return an integer specifying the maximum number of elements that sum up to the target. Return 0
if there is no match.
Test Case Example
Input:
4
10
2 3 5 5
Output:
3
Explanation:
Possible combinations of elements that sum to 10 are:
- Combination 1: 2, 3, 5 (Total elements: 3)
- Combination 2: 5, 5 (Total elements: 2)
The optimal solution uses 3 elements: 2, 3, and 5.