Hi,
You can use two different data structure to maintain the time complexity.
Max-Heap
Hash Map
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.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi,
You can use two different data structure to maintain the time complexity.
Hash Map
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.
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.