Solution:
1. Read each line, extract customer id and price.
2. Maintain a hash in which key is customer id and value is pointer to struct defined as below -
struct details
{
long totalPrice;
int count;
};
3. For each transaction do
i. hash[customerId]->totalPrice += extractedPrice;
ii. hash[customerId]->count++;
4. Now for given customer, average price = hash[customerId]->totalPrice / hash[customerId]->count;
1. Read each line, extract customer id and price.
2. Maintain a hash in which key is customer id and value is pointer to struct defined as below -
struct details
{
long totalPrice;
int count;
};
3. For each transaction do
i. hash[customerId]->totalPrice += extractedPrice;
ii. hash[customerId]->count++;
4. Now for given customer, average price = hash[customerId]->totalPrice / hash[customerId]->count;
No comments:
Post a Comment