Lets say we need to design a ranked choice voting system. A single person votes by handing in an ordered array of names.
Rule 1 Candidates are given 3 points for 1st place, 2 points for 2nd and 1 point for 3rd place. Given an array of arrays of names, return the candidates in order of most points to least.
Rule 2 In the event of a tie, return the candidate who reached the winning points first
e.g.
“alice”, “bob”, “charlie” // alice – 3; bob – 2; charlie – 1
“alice”, “bob”, “charlie” // alice – 3; bob – 2; charlie – 1
“charlie”, “alice”, “bob” // alice – 2; bob – 1; charlie – 3
Result – [alice, charlie, bob]
In this scenario, Alice has 8 points, while both Bob and Charlie have 5 points each. However, since it’s a tie between Bob and Charlie, the deciding factor is who reached the winning points first according to the rules. Charlie reached 5 points before Bob did, making him the winner.
Can some one please help with different approaches to solve this problem.
Gopal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.