Page 3 of 3

Re: 11088 - End up with More Teams

Posted: Tue Dec 15, 2009 9:15 pm
by Taman
Towhid wrote:
mf wrote:
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.
It fails this test case:

Code: Select all

7
2 4 6 6 7 9 9
Your greedy would choose 9,2,9 as the first team, and wouldn't be able to make a second team.
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.
well, no comments, just another test case.
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.