my code works well in indexing all votes in the preferences except for the first one, I tried debugging and it worked well for all indexes including the first one..!

enter image description here

enter image description here


From the spec:

The array preferences[i] will represent all of the preferences for voter number i, and the integer preferences[i][j] here will store the index of the candidate who is the jth preference for voter `i.

So j represents the preference (rank).

In this program the ith index (which is analagous to the jthe index from the spec) represents the candidate index.

Try/debug an election with 3 candidates (a, b, c) and 3 voters who cast the following ballots:

  • c b a
  • c a b
  • c a b

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .