Minimum Additions for Range Coverage

Company: Amazon Ml school_3aug

Difficulty: medium

Problem Statement

Minimum Additions for Range Coverage You are given a list A of positive integers sorted in non-decreasing order, and a target B . A value v is formable if some sub-collection of the list (each element used at most once) adds up to exactly v . You may insert extra positive integers of your choice into the list. Find the smallest number of insertions after which every integer from 1 to B (inclusive) is formable. Function description Complete the function minAddition with the following parameters: INTEGER_ARRAY A : the sorted list of positive integers INTEGER B : every value from 1 to B must become formable Returns INTEGER : the minimum number of integers that must be inserted. Input format The first line contains the integer N , the length of A . The second line contains N space-separated integers A[0], A[1], ..., A[N-1] . The third line contains the integer B . Output format Print a single integer: the minimum number of insertions. Constraints 1 <= N <= 1000 1 <= A[i] <= 10^