← HubSpot Interview Insights

HubSpot·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

HubSpot technical phone screen for a software engineer role, one algorithmic problem the whole time. The question was a classic graph/search-adjacent puzzle dressed up with an API constraint, which made it trickier than it looked on the surface.

Questions Asked (1)

Q1

Given n people at a party, use a knows(a, b) API to find a 'celebrity': someone known by everyone else but who knows no one. Minimize the number of API calls, ideally to O(n). Return -1 if no such person exists.

Algorithms & Data StructuresAPI & Integrations
Author's notes

The O(n) part is what separates people who get it from people who brute-force it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pass elimination strategy: first, find a candidate by iterating through people and eliminating anyone who is known by the current candidate (since a celebrity knows no one). Then, verify the candidate by checking that they are known by everyone else and know no one, returning -1 if verification fails.

Pro tip: During elimination, each knows(a, b) call eliminates exactly one person, so you need at most n-1 calls to find a candidate. This guarantees O(n) calls, and the verification pass adds at most 2(n-1) calls, keeping the total linear.

1. Clarify the problem and constraints

Confirm that the knows(a, b) API returns true if a knows b, and that a celebrity is known by all others but knows none. Discuss edge cases like n=0, n=1, and multiple potential celebrities.

2. Find a candidate via elimination

Initialize candidate = 0. For each person i from 1 to n-1, if knows(candidate, i) is true, then candidate knows i, so candidate cannot be a celebrity; set candidate = i. Otherwise, i knows candidate, so i cannot be a celebrity; keep candidate unchanged.

3. Verify the candidate

For every other person i, check that knows(candidate, i) is false (candidate knows no one) and knows(i, candidate) is true (everyone knows candidate). If any check fails, return -1.

4. Analyze complexity and optimize

Explain that the elimination pass uses at most n-1 calls, and verification uses at most 2(n-1) calls, totaling O(n) API calls. Mention that this is optimal since each call can eliminate at most one person.

5. Handle edge cases and return result

If n is 0, return -1. If n is 1, the single person is trivially a celebrity (assuming the definition holds), but verify if needed. Return the candidate index if verification succeeds, otherwise -1.

Key Points to Mention

  • The elimination strategy reduces the candidate set by one per API call, ensuring O(n) calls.
  • Verification is necessary because elimination only guarantees a candidate, not an actual celebrity.
  • The total number of API calls is at most 3n-3, which is O(n).
  • Edge cases: n=0, n=1, and the possibility of no celebrity.
  • The algorithm is optimal because each knows(a, b) call can at best eliminate one person from being the celebrity.
  • Space complexity is O(1) as only a few variables are used.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.