Question bank › Stack
Dsa Stack Medium

Celebrity Problem using a Stack

Suppose you are at a party with n people (numbered from 0 to n-1). A person is a celebrity if they are known by everyone else but know no one. Given a 2D array of known where known[i][j] is true if person i knows person j, write a program to find out if there's a celebrity at the party. Input format: The first line contains an integer n, followed by n lines each containing n integers (0 or 1) representing the known matrix. Output format: Print the index of the celebrity or -1 if there is no celebrity. Example: Input: 3 0 1 0 0 0 0 1 1 0 Output: 1

Key concepts

stackcelebrityrelationships

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.