PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/HubSpot

Find a special person using knows(a,b)

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic reasoning about pairwise relation inference using an oracle-style knows(a, b) API and the ability to minimize API calls, testing skills in graph modeling and asymptotic analysis.

  • easy
  • HubSpot
  • Coding & Algorithms
  • Software Engineer

Find a special person using knows(a,b)

Company: HubSpot

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

## Problem You are given `n` people labeled `0` to `n-1` at a party. You can call an API: - `knows(a, b) -> bool`: returns `true` if person `a` knows person `b`, otherwise `false`. A **special person** is defined as someone who: 1. Is **known by everyone else** (for all `i != x`, `knows(i, x) == true`), and 2. **Knows nobody else** (for all `i != x`, `knows(x, i) == false`). Return the label of the special person if one exists, otherwise return `-1`. ## Constraints - `1 <= n <= 10^4` - You should minimize the number of API calls; aim for **O(n)** calls. ## Notes - `knows(a, a)` is undefined and should not be relied upon.

Quick Answer: This question evaluates algorithmic reasoning about pairwise relation inference using an oracle-style knows(a, b) API and the ability to minimize API calls, testing skills in graph modeling and asymptotic analysis.

Related Interview Questions

  • Validate hiring request under role constraints - HubSpot (medium)
  • Design and implement a bank account system - HubSpot (Medium)
  • Design file deduplication at scale - HubSpot (Medium)
  • Design a bank with scheduled payments and merges - HubSpot (Medium)
  • Implement Python LRU cache with varargs - HubSpot (Medium)
HubSpot logo
HubSpot
Dec 15, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
12
0

Problem

You are given n people labeled 0 to n-1 at a party. You can call an API:

  • knows(a, b) -> bool : returns true if person a knows person b , otherwise false .

A special person is defined as someone who:

  1. Is known by everyone else (for all i != x , knows(i, x) == true ), and
  2. Knows nobody else (for all i != x , knows(x, i) == false ).

Return the label of the special person if one exists, otherwise return -1.

Constraints

  • 1 <= n <= 10^4
  • You should minimize the number of API calls; aim for O(n) calls.

Notes

  • knows(a, a) is undefined and should not be relied upon.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More HubSpot•More Software Engineer•HubSpot Software Engineer•HubSpot Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.