Skip to content

Commit 28e90b2

Browse files
committed
Create README - LeetHub
1 parent 3ef8b32 commit 28e90b2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

The Celebrity Problem - GFG/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# The Celebrity Problem
2+
## Medium
3+
<div class="problem-statement">
4+
<p></p><p><span style="font-size:18px">A celebrity is a person who is known to all but does not know anyone at a party. If you go to a party of N people, find if there is a celebrity in the party or not.<br>
5+
A square NxN matrix M[][] is used to represent people at the party such that if an element of row i and column j &nbsp;is set to 1 it means ith person knows jth person. Here M[i][i] will always be 0.<br>
6+
<strong>Note:</strong> Follow 0 based indexing.</span><br>
7+
&nbsp;</p>
8+
9+
<p><strong><span style="font-size:18px">Example 1:</span></strong></p>
10+
11+
<pre><span style="font-size:18px"><strong>Input:</strong>
12+
N = 3
13+
M[][] = {{0 1 0},
14+
{0 0 0},
15+
{0 1 0}}
16+
<strong>Output:</strong> 1
17+
<strong>Explanation: </strong>0th and 2nd person both
18+
know 1. Therefore, 1 is the celebrity. </span></pre>
19+
20+
<p><br>
21+
<span style="font-size:18px"><strong>Example 2:</strong></span></p>
22+
23+
<pre><span style="font-size:18px"><strong>Input:</strong>
24+
N = 2
25+
M[][] = {{0 1},
26+
{1 0}}
27+
<strong>Output:</strong> -1
28+
<strong>Explanation: </strong>The two people at the party both
29+
know each other. None of them is a celebrity.</span></pre>
30+
31+
<p><br>
32+
<span style="font-size:18px"><strong>Your Task:</strong><br>
33+
You don't need to read input or print anything. Complete the function <strong>celebrity()</strong> which takes the matrix M and its size N as input parameters and returns the index of the celebrity. If no such celebrity is present, return -1.</span></p>
34+
35+
<p><br>
36+
<span style="font-size:18px"><strong>Expected Time Complexity:</strong> O(N)<br>
37+
<strong>Expected Auxiliary Space:</strong> O(1)</span></p>
38+
39+
<p><br>
40+
<span style="font-size:18px"><strong>Constraints:</strong><br>
41+
2 &lt;= N &lt;= 3000<br>
42+
0 &lt;= M[][] &lt;= 1</span></p>
43+
<p></p>
44+
</div>

0 commit comments

Comments
 (0)