Skip to main content

Cisco

Cisco OA 2022 - Max Elements Sum up to Target

Problem:

Find the maximum number of elements in a given array that sum up to a given target.

Constraints:

  • The second: 25.

Input:

  1. The first line specifies the number of elements in the array
  2. The second line specifies the target.
  3. 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.

Example

Input:

4
10
2 3 5 5

Output: 3


Explanation:
Possible combinations:
- 2, 3, 5 (Total elements: 3)
- 5, 5 (Total elements: 2)
The solution is 3 elements (2, 3, and 5).