The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

very hard algorithm implementation

So I wanted to solve this problem:

After a tennis tournament each player was asked how many matches he had.
An athlete can't play more than one match with another athlete.
As an input the only thing you have is the number of athletes and the matches each athlete had. As an output you will have 1 if the tournament was possible to be done according to the athletes answers or 0 if not. For example:

the first number of the input is not part of the athletes answer it's the number of athletes that took part in the tournament for example in 6 2 4 5 5 2 1 we have 6 athletes that took part and their answers were 2 4 5 5 2 1

Re: very hard algorithm implementation

Hi TheByt3, I know I am replying a bit late, but I just saw your question, and think maybe I'd help you a bit. Here algorithm would work so:
You should initially determine the maximum of the series you indicate, and decrease the other ones in the series by one, then we'd make the maximum number 0, and keep processing the same algorithm for the next maximum numbers remaine. For instance, say the series is as follows: 6 4 1 1 1 2 1. Here 6 indicates the number of players, we can start processing by the maximum number of the series, being 4. Decrease 1, 1, 1, and 2 by one so the result is 0 0 0 0 1 1. The maximum is, now, 1, afterwards the series get converted to 0 0 0 0 0 0, so the function should return the result true. The code is as follows (I hope it helps):