Company: Bank_Of_America
Difficulty: medium
Maximum Consecutive Products Reeta is at a store with a budget of X . The store has N items on one long shelf, and the item in position i costs arr[i] . Reeta refuses to walk around comparing prices. She will pick one run of neighbouring items off the shelf -- items that sit next to each other, with nothing skipped in between -- and buy all of them, as long as their costs add up to at most X . She may also walk out with nothing. Report how many items the longest affordable run holds. Implement numberofProducts(n, x, arr) ; it returns that count. Input Format The first line holds two integers N and X : the number of items and the budget. The second line holds N integers, the cost of each item in shelf order. Output Format Print one integer, the number of items in the longest run whose costs add up to at most X . Constraints 1 <= N <= 2000 (inferred -- the constraints block in the source capture is garbled and the version stored with this question, 3 <= arr[i] <= 200 together