Join Regular Classroom : Visit ClassroomTech

Wipro NLTH Coding Solve | Gift Hampers to Winners | Codewindow.in

The manager of a supermarket wants to organize an event in which he will distribute gift hampers to the winners of the event. The manager has planned in such a way that each customer has to pick the product in a pair and each pair has different types of products. Any two customers can’t pick the same type of product pair but the price may be same. There are N types of products and each product has a price. He will offer the gift hampers to those customers for whom the difference of the price of the products pickedby them is equal to the given integer value K. Write an algorithm to help the Manager find the total numbers of lucky customers who will get the gift hampers.

Input
ProductTypes : an integer representing the types of products(N).
numK, an integer representing the given value K.
prices, a list of integers representing the price of the products.

Output
return a integer representing the total number of lucky customers who will get the gift hamper.

Constraints
NA

Example

Input:
6
13
10 15 23 14 2 15

Output:
3

Explanation:
NA

#include<stdio.h>
int main()
{
    int n, numk;
    int i,j,c=0;
    scanf("%d",&n);
    scanf("%d",&numk);
    int prices[n];
    for(i=0;i<n;i++)
        scanf("%d",&prices[i]);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if((prices[i]-prices[j]==numk)||(prices[j]-prices[i]==numk))
                c++;
        }
    }
    printf("%d",c);
    return 0;
}

Also Checkout

Recent Posts
Categories
Pages