McKinsey | OA | Data Engineer | [Programming Problem] Choose A Flask

An olive oil seller needs to measure oi; for customers using only one type of flask. There are many flasks available, each with marking at various levels. Each customer must receive a flask filled to a mark that is atleast equal to the amount ordered. Given a list of customer requirements and a list of flasks with their measurements, determine the single type of flask that will result in the minimal loss to the merchant. Waste is the sum of marking – requirement for each order. Return the zero-based index of the flask type chosen. If there are multiple answers, return the minimum index. If no flask will satisfy the constraints, return -1.
For example, there are n=3 orders for requirements = [10, 15] units of oil.
Markings: [[0,11],[0,15],[1,17],[1,12],[1,16],[2,10],[2,21],[2,19],[2,18]]
Waste from flask 0-> 11-10 = 1 , 15-15=0 i.e 0+1 = 1
Waste from flask 1-> 12-10 =2, 16-15=1 i.e 2+1 = 3
Waste from flask 2-> 10-10=0, 18-15=3 i.e 0+3=3
hence we return flask type 0 as solution cause it causes the minimum waste
Note ! The markings 2d array will be given in order of the flasks, i.e the markings for the 0-index flask will be followed by markings of 1-index flask and so on. For each flask, the given markings will also be in the sorted order.
Sample inputs:
3
[10,15]
[[0,11],[0,15],[1,17],[1,12],[1,16],[2,10],[,2,21],[2,19],[2,18]]
Sample Output :
0

Need optimized solution! Marking, requirements list can be very large

Comments (1)