using System.Collections.Generic;
private bool[,] knowsMatrix;
public Solution(bool[,] matrix)
private bool Knows(int a, int b)
return knowsMatrix[a, b];
public int FindCelebrity(int n)
Stack<int> stack = new Stack<int>();
for(int i = 0; i < n; i++)
int candidate = stack.Pop();
for(int i = 0; i < n; i++)
if(Knows(candidate, i) || !Knows(i, candidate))
public static void Main()
Solution solution = new Solution(matrix);
int result = solution.FindCelebrity(3);
Console.WriteLine("Celebrity Index : " + result);