I have an offer configured with discount values and applicable volume range.
Its possible multiple offers applicable for a product, so I am looking for algorithm to consolidate overlapping volume range among various offers and show final discount applicable. Below code snippet would help to visualize the ask :
class VolumeTierRange
{
public int Min { get; set; }
public int Max { get; set; }
public int Discount { get; set; }
}
/* Offer1Range */
List<VolumeTierRange> Offer1Ranges = new List<VolumeTierRange>{
new VolumeTierRange {Min=1, Max=20, Discount=2 },
new VolumeTierRange {Min=21, Max=49 , Discount=10 },
new VolumeTierRange {Min=50, Max=100 , Discount=5 },
new VolumeTierRange {Min=101, Max=1000, Discount=15}
};
/* Offer2Range */
List<VolumeTierRange> dicountBRanges = new List<VolumeTierRange>{
new VolumeTierRange {Min = 1, Max=50, Discount=6},
new VolumeTierRange {Min=51, Max=1000, Discount=10 }
};
Consolidated result would look like :
List<VolumeTierRange> effectiveDiscount = new List<VolumeTierRange>{
new VolumeTierRange {Min=1, Max=20, Discount=8 },
new VolumeTierRange {Min=21, Max=49, Discount=16},
new VolumeTierRange {Min=50, Max=50, Discount=11},
new VolumeTierRange {Min=51, Max=100, Discount=15},
new VolumeTierRange {Min=101,Max=1000,Discount=25}
};
I do have some ways to achieve the expected outcome, but those all does not seems to be very intuitive.
Additional Info: Min value of first item and Max value of all offers is fixed (like 1 and 1000 in this example). Also there cannot be discontinuity while defining volume range.