Skip to main content

Accenture

Accenture OA-11 2024

Problem Description

Bob goes to a supermarket to buy candies represented by an array A for a Halloween party. His mother gave him M amount of money. Due to the festive season, there are several offers in the supermarket. One such offer useful for Bob is, if the price of the candy is a multiple of 5, he can buy it without spending any money. Otherwise, he will spend money equal to Ai which is the price of a particular candy. Bob can shop as long as he has money. Your task is to find and return the maximum number of candies Bob can buy.

Note: Assume 1-based indexing.

Input Format:

  • input1: An integer value, representing the number of candies.
  • input2: An integer array A, representing the price of each candy.
  • input3: An integer value M, representing the amount of money.

Output Format:

Return the number of candies Bob can buy.

Constraints:

  • 1 <= N <= 10^5
  • 1 <= A[i] <= 10^9
  • 0 <= M <= 10^9

Example

Sample Input:

input1: 3
input2: [5, 5, 105]
input3: 16

Sample Output:

5

Explanation:
Bob can buy the first two candies for free as their prices are multiples of 5. He can also buy the third candy using his remaining money (16 - 0 = 16). Therefore, the maximum number of candies Bob can buy is 3.