DEV Community

Discussion on: Top 8 Data Structures for Coding Interviews and practice interview questions

Collapse
 
babygame0ver profile image
babygame0ver • Edited

Hi,
You can use two different data structure to maintain the time complexity.

  1. Max-Heap
  2. Hash Map

  3. Hash-Map to put all the products for efficient lookup
    Go through all the offers and check whether their elements exist in Hash-map.
    If yes , put them in heap.

  4. Max-Heap will contain discounts in descending order but before inserting into heap you need to check that the list of order with id's belongs to product like Product I'd [1,3,8] doesn't belong to original list of these : This is step 1
    products [1,2,3,5,7,6,9]

After Insertion you can get Max discount in o(1) in max-heap.