dsa · medium

The Celebrity Problem

GreyOrangeArrayTwo Pointers

knows is an n×n 0/1 matrix (knows[i][j]=1 means i knows j). A celebrity is known by everyone and knows nobody (ignore the diagonal). Return their index, or -1.

Arguments

**Example**

`` Input: [[0,0,1],[0,0,1],[0,0,0]] Output: 2 ``

Constraints

1 <= n <= 100 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[[0,0,1],[0,0,1],[0,0,0]]

Expected:
2

Example 2

Input:
[[0,1],[1,0]]

Expected:
-1

Open in the Dojo editor