Skip to content

Solution to Array/Celebrity Problem #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

evilegg
Copy link
Contributor

@evilegg evilegg commented Jun 27, 2017

I wrote a solution to the celebrity problem based on the description that I've run into. It's in python and not cpp, but it might be useful. It's got two solutions: the straightforward one and the clever one.

Running it results in the following (numbers in parens is number of times HaveAcquaintance() is called):

$ python problem/Array/CelebrityProblem.py

D_IS_THE_CELEBRITY {'a': ('b', 'c', 'd'), 'c': ('a', 'd'), 'b': ('c', 'd'), 'e': ('b', 'd'), 'd': ()}
PASS NSquaredSolution(40): d
PASS TwoPointersSolution(12): d

NO_CELEBRITY {'a': ('b', 'c', 'd'), 'c': ('a', 'd'), 'b': ('c', 'd'), 'e': ('b', 'd'), 'd': 'e'}
PASS NSquaredSolution(40): None
PASS TwoPointersSolution(11): None

ALMOST_A_CELEBRITY {'a': ('b', 'c', 'd'), 'c': ('a', 'd'), 'b': ('c', 'd'), 'e': 'b', 'd': ()}
PASS NSquaredSolution(40): None
PASS TwoPointersSolution(6): None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant