Description
Solutions
Submission
Shopping Cart Billing 🌻
🤘 INTERN

An e-commerce company is currently celebrating ten years in business. They are having a sale to honor their privileged members, those who have been using their services for the past five years. They receive the best discounts indicated by any discount tags attached to the product. Determine the minimum cost to purchase all products listed. As each potential price is calculated, truncate it to its integer part before adding it to the total. Return the cost to purchase all items as an integer.

There are three types of discount tags:

  • Type 0: discounted price, the item is sold for a given price.
  • Type 1: percentage discount, the customer is given a fixed percentage discount from the retail price.
  • Type 2: fixed discount, the customer is given a fixed amount off from the retail price.
  • Function Description

    Complete the function findLowestPrice in the editor below.

    findLowestPrice has the following parameter(s):

    • String[][] products: a 2D array of product descriptors as strings: price followed by up to m-1 discount tags
    • String[][] discounts: a 2D array of tag descriptors as strings: tag, type, amount

    Returns

    int: the total amount paid for all listed products, discounted to privileged members' pricing

    Example 1:

    Input:  products = [["10", "d0", "d1"], ["15", "EMPTY", "EMPTY"], ["20", "d1", "EMPTY"]], discounts = [["d0","1","27"],["d1", "2", "5"]]
    Output: 35
    Explanation:
    1. If a privileged member buys product 1 listed at a price of 10 with two discounts available:
  • Under discount d0 of type 1, the discounted price is 10 - 10 * 0.27 = 7.30, round to 7.
  • Under discount d1 of type 2, the discounted price is 10 - 5 = 5.
  • The price to purchase the product 1 is the lower of the two, or 5 in this case.
  • 2. The second product is priced at 15 because there are no discounts available. 3. The third product is priced at 20. Using discount tag d1 of type 2, the discounted price is 20 - 5 = 15. The total price to purchase the three items is 5 + 15 + 15 = 35.
    Constraints:
      • 1 ≤ n, m, d ≤ 1000
      • tags are not unique
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: