Challenge: Find the Celebrity

Try to solve the Find the Celebrity problem.

We'll cover the following

Statement

In a gathering of NN individuals (labeled from 00 to N1N-1), there’s a possibility of one person being a celebrity. A celebrity is characterized by being known by everyone else and not knowing any attendees. This scenario is represented using an N×NN \times N binary matrixmatrix, where each cell contains either a 00 or a 11. If matrix[i][j]=1matrix[i][j] = 1, it signifies that person ithi^{th} knows the jthj^{th} person.

For the given matrixmatrix, determine the existence of a celebrity within the group. If a celebrity is identified, return its label, otherwise return 1-1.

Constraints:

  • N=matrix.length=matrix[i].lengthN = matrix.length = matrix[i].length
  • 2N1002 \leq N \leq 100
  • matrix[i][j]matrix[i][j] is 00 or 11.

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.