well, no comments, just another test case.Towhid wrote:But When there are 7 persons, I know I can form at most 2 teams. So, I use only the higher 6 persons and ignore the person with value 2. I think, the greedy works nicely.mf wrote:It fails this test case:kp wrote:Among all pairs with minimum sum of values I always take the one with minimum first element. So my code passes your test case.Your greedy would choose 9,2,9 as the first team, and wouldn't be able to make a second team.Code: Select all
7 2 4 6 6 7 9 9
9
2 4 6 6 7 9 9 1 1
That greedy approach will return the output 1, while the output should be 2. Here is no way to avoid that 2 that you have ignored in the case of 7 people.