Solution to Equi-Leader by codility

24 Jan

Question: http://codility.com/demo/take-sample-test/equi_leader

Question Name: EquiLeader

A variant of the previous question.

12 thoughts on “Solution to Equi-Leader by codility

  1. Here’s my C solution :

  2. Adding my Java Solution 100/100
    https://codility.com/demo/results/demoZSME5G-RXN/

  3. Well, again, I was numb to recognize the fact equileader exists if and only if it is the leader of the sequence. Fortunately, codility is kind this time and allows space complexity to be O(N). This gives me the opportunity to apply the old hashtable trick here. An extra vector is needed to store the leader-end-here. And then scan the sequence backward to find the leader starting from N-1 to 1, so we can compare the backward leader with the leader-end-here saved in the vector.
    I have to admit my solution is silly though…

  4. Sheng, alternatively, you can detect leader by comparing candidate_count > 0, if it is true, then candidate is definitely a leader, otherwise there is no leader in array.

  5. You are right: Python might be slow, but it really makes my code shorter…Well, comparing with the dummy solution I submitted last year ^_^

Leave a Reply

Your email address will not be published. Required fields are marked *