
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.
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”.
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.
Print the result till 5 decimal places
You do not need to print anything; it has already been taken care of. Just implement the given functions.
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
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 multiply the quantity by the price of each product they purchased.
We also keep a count of previous customers and increase it as soon as generateBill is called. If this count is divisible by ‘N’, we simply apply the discount and return the bill amount.
Algorithm: