I have included my approach and solution. My solution works fine, however, is unoptimized with O(n^3) complexityAn NGO is running seed distribution program. It has limited quantity of varied quality seeds. In order to get seeds, farmer needs to request number of seeds. Seed distribution happens only on Sunday with goal that maximum farmers gets best quality seeds of same type.Consider, NGO has following seeds and count (Ordered by quality - Top is highest):|Quality|Fruit1|Fruit2|Fruit3||-------|------|------|------||Highest|     3|     3|     1||Medium |     2|     0|     0||Low    |     4|     0|     0|Required Seeds:Farmer 1: 2Farmer 2: 3Farmer 3: 1Farmer 4: 2Farmer 5: 3Output: Goal is to assign highest quality seeds to maximum farmers.Farmer 1: Highest Fruit1Farmer 2: Highest - Fruit2Farmer 3: Highest - Fruit1Farmer 4: Medium - Fruit1Farmer 5: Low - Fruit1Here, farmer 1 and 3 in combination requested for 3 seeds, hence, in combination got highest fruit1.My approach (Pseudocode)I have a following domain classes - Farmer, , QualityType, FruitType, SeedsQualityType has list of FruitType which has list of seeds.To obtain result, I am doing following:Iterate from highest Quality type to lowest.nested iterate to fruit type and seeds.For any seeds, check if we have farmer1 asking for same number of seeds - either alone or in combination with any one else.If not move to farmer two.This works however isn't optimized as it has 3 nested loops.Can you please suggest any algorithm that can simplify it?
Seeds distribution algorithm with complexity better than O(n^3)?
algorithms;complexity;big o