Back to November Back to Year 2026
MEDIUM 30 Nov 2026 View on LeetCode

1357. Apply Discount Every n Orders

</> Solution

/**
 * Problem: LeetCode 1357 - Apply Discount Every n Orders
 * Difficulty: Medium
 * Language: Java
 * Author: CodeByTushu
 */
import java.util.HashMap;
import java.util.Map;

class Cashier {
    private int n;
    private int discount;
    private int count;
    private Map<Integer, Integer> priceMap;

    public Cashier(int n, int discount, int[] products, int[] prices) {
        this.n = n;
        this.discount = discount;
        this.count = 0;
        priceMap = new HashMap<>();
        for (int i = 0; i < products.length; i++) {
            priceMap.put(products[i], prices[i]);
        }
    }

    public double getBill(int[] product, int[] amount) {
        count++;

        long bill = 0;
        for (int i = 0; i < product.length; i++) {
            bill += (long) amount[i] * priceMap.get(product[i]);
        }

        // Har n-th customer ko discount milta hai
        if (count % n == 0) {
            return bill * (100 - discount) / 100.0;
        }
        return (double) bill;
    }
}

/**
 * Your Cashier object will be instantiated and called as such:
 * Cashier obj = new Cashier(n, discount, products, prices);
 * double param_1 = obj.getBill(product,amount);
 */

TIME COMPLEXITY

O(K)

SPACE COMPLEXITY

O(1)

TOPICS

Array Data Stream Data Structure Ordered Set Simulation