Back to problems

Find a special person using knows(a,b)

Algorithm · Hubspot · Medium

Imagine a party with n guests numbered from 0 to n - 1. You are allowed to call a helper API knows(a, b) that reports whether guest a knows guest b; it returns true or false. A guest x is considered the special guest when both of these requirements are met: every other guest knows x: for every i distinct from x, knows(i, x) is true; x knows no other guest: for every i distinct from x, knows(x, i) is false. If such a guest is present, return its label. Otherwise, return -1.…

Checking your access…