Algorithm · Salesforce · Medium
In a party, there are n people labeled from 0 to n-1. Among them, a celebrity may be present. A celebrity is someone who does not know any other attendee, and every other attendee knows the celebrity. You cannot ask the attendees directly; instead, you have access to a function knows(a, b) that returns true if person a knows person b, and false otherwise. Implement a function that returns the label of the celebrity if one exists; if no celebrity is at the party, return -1.…
Checking your access…