**Question**: An** e-commerence company is planning to give a special discount** on all of it’s products to its customers for the christmas holiday. The company possesses data on it’s stock of N product type. The data for each product type represents the count of customers who have ordered the given product. If the fata k is positive then it shows that the product has been ordered y k customers and is in stock. If the data k is negative then it shows that it has been ordered by k customers but it is not available in stock.The company will fulfill it from warehouse. They are planning to offer a discount amount A for each product. The discount value will be distributed to the customers who have purchased that selected product. The discount will be distributed only if the decided amount A can be divided bu the number of orders for a particular product.

write an **algorithm **for sales team to find the number of products out of N for which the discount will be distributed.

**Input:**

The first line of the input consists of an integer – numOfProducts, represnting the number of different types of products ( N).

The second line consists of the respective product types

The last line consists of an integer -disAmount, representing the discount amount that will be distributed among the customers.

**Output**:

Print an integer representing the number of products out of N for which the discount will be distributed.

**Examples:**

**Input:**

7

9 -13 8 -7 -8 18 10

18

**output:**

2

**Explanation:**

Here in given array we can observe 18 is divisibleby 9 and 18 itself so output is 2.

**Algorithm to Solve **

- Take input from user total number of customers (N), array of integers representing ordered value of customers, then an integer representing discount amount say key.
- Use a for loop to iterate through all the elements of array.
- Use two conditions inside if block the that is
**The number should divide key completely****The number should be greater than ZERO (positive number).**

- Take a result variable and initialize it to zero.
- Each time a number satisfies step 3 conditions, increment the result by 1.
- At the end print the result variable.

**JAVA CODE **

package arrayproblems; import java.util.*; class Problem20 { public static void main(String[] args) { int N=7; int[] array1= {9,-13,8,-7,-8,18,10}; int key=18; int res=0; for(int i=0;i<array1.length;i++) { if(key%array1[i]==0 && array1[i]>0) { res++; } } System.out.println(res); } }

**Watch Complete Explanation for Above code On our Channel **

**Similar Off Campus Coding Questions **

Count Buildings Hacker Earth coding question with solution

Maximum Work Hacker Earth Problem solved

Pingback: APPSIAN off Campus Coding Question - Is It Actually