Black Friday

It’s black friday and the supermarket near Ninja’s house is offering a special discount to every Nth customer that generates a bill. You are initially given 2 arrays, “PRODUCTS” and “PRICES” where “PRODUCTS[i]” represents the ID of the ith product and “PRICES[i]” represents the price of the ith product per unit. You are also given an integer “DISCOUNT” which represents the discount percentage for every nth customer (i.e. the effective amount to be paid would be ‘(100 - discount) / (100 * amount’).

For each customer that visits the store, you are given 2 arrays, “PRODUCTID” and “QUANTITY” where “PRODUCTID[i]” represents the ID of the ith product and “QUANTITY[i]” represents the quantity of the ith product purchased by the customer.

Your task is to implement the following 2 functions:

1. blackFriday(int N, int discount, int[] products, int[] prices) where every Nth customer receives a discount, “discount” is the discount percentage, “products” contains the product IDs, and “prices” contains the prices of products.

2. generateBill(int[] productID, int[] quantity) where “productID” contains the product IDs and “quantity” contains the quantities of products purchased by the customer.
Input Format
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.

The first line contains three space-separated integers ‘N’, “discount” and ‘S’ denoting the customer’s getting a discount, discount percentage and number of products.

The next line contains ‘S’ space-separated integers denoting the array “products”.

The next line contains ‘S’ space-separated integers denoting the array “prices”.

The next line of each test case contains an integer ‘K’ denoting the number of queries.

For the next K  queries:
The first line contains an integer ‘S’ denoting the number of distinct products purchased.
The next line contains ‘S’ space-separated integers denoting the array “productID”.
The next line contains ‘S’ space-separated integers denoting the array “quantity”.
Output Format :
For each test case, return a list containing the bill amount for each customer after discount(if applicable) in the order they generated the bill.

Output for each test case will be printed in a new line. 
Note:
Print the result till 5 decimal places
Note:
You do not need to print anything; it has already been taken care of. Just implement the given functions.
Constraints:
1 <= T <= 100
1 <= K <= 1000
1 <= S <= 100
1 <= productID[i], products[i], quantity[i], prices[i] <= 1000

Where ‘T’ denotes the number of test cases,
‘K’ denotes the number of queries and
‘S’ denotes the number of products

Time Limit: 1sec
CodingNinjas
author
2y
Counting Number of Previous Customers

We can simply start by creating a hashmap that stores each product ID and corresponding price. For each customer, calculating the bill amount is simple, just multi...read more

Help your peers!
Add answer anonymously...
Cognizant Trainee Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter