Saturday, September 5, 2015

LeetCode [277] Find the Celebrity

=============

  • Line 8-13 computes c, which is the only possible celebrity
  • Proof:
    • if c=0, c does not know any one in [1...n-1]. [c+1...n-1] are not celebrities.
    • if c=1, 0 knows 1. Thus 0 is not celebrity and [c+1...n-1] are not celebrities.
    • if c=2, there are 2 cases. In both cases 0 and 1 are not celebrities. Also, [c+1...n-1] are not celebrities.
      1. 0 knows 1 and 1 knows 2. 
      2. 0 does not know 1 but 0 knows 2. 
    • if c=i, [0, i-1] and [i+1, n-1] are not celebrities.

Ref
[1] https://leetcode.com/problems/find-the-celebrity/
[2] http://www.geeksforgeeks.org/the-celebrity-problem/

No comments:

Post a Comment