Find the Celebrity
knows[i][j] is 1 if person i knows person j. A celebrity is known by everyone else and knows nobody else. Return the celebrity's index, or -1 if there is none.
Requirements
- questions: eliminate one candidate per comparison.
Examples
EXAMPLE WALKTHROUGHperson 1
A guided view of the published example, not a trace of your code.
INPUT
[[[0,1,0],[0,0,0],[0,1,0]]]TASKfind_the_celebrity()
EXPECTED OUTPUT
1Start with the input values shown in this example.
Example 1 of 3
Input: knows = [[0,1,0],[0,0,0],[0,1,0]]
Output: 1
Explanation: person 1
Input: knows = [[0,1],[1,0]]
Output: -1
Explanation: no celebrity
Input: knows = [[0]]
Output: 0
Explanation: alone
Hint 1
If a knows b, a can't be the celebrity; otherwise b can't be.
Hint 2
After one pass, verify the single remaining candidate.