FastPrepDirect Manager and Peer Queries
Problems/Direct Manager and Peer Queries

Direct Manager and Peer Queries

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the operations manager(a,b), peer(a,b), and is_manager(a,b), and what each one means. It does not say whether manager means direct or any level above. It also leaves out how a batch is written, how queries relate to time, what to do with conflicting facts, the examples, and the input limits. Here we use direct-manager facts, an array of tagged operations, queries answered as they come, consistent updates, and clear limits. Our version is about 75% the same as the reported question.

There are personCount people numbered from 0 through personCount - 1. Process the relationship operations from first to last.

  • [0, a, b] records that person a is the direct manager of person b.
  • [1, a, b] records that persons a and b are peers, meaning they have the same direct manager.
  • [2, a, b] asks whether the facts recorded so far prove that person a is the direct manager of person b.

All update operations are mutually consistent. A query whose manager is not yet known returns false.

Return the answers to all type-2 operations in their original order.

Function

answerManagerQueries(personCount: int, operations: int[][]) → boolean[]

Examples

Example 1

personCount = 5operations = [[0,0,1],[1,1,2],[2,0,2],[2,3,2]]return = [true,false]

Person 0 manages person 1. Because 1 and 2 are peers, person 0 also manages person 2. Person 3 is not their manager.

Example 2

personCount = 3operations = [[2,0,1],[0,0,1],[2,0,1],[1,1,2],[2,0,2]]return = [false,true,true]

The first query is false because person 1's manager is still unknown. The manager assertion answers the second query, and the later peer assertion propagates that manager to person 2.

Example 3

personCount = 5operations = [[1,1,2],[0,4,2],[2,4,1],[0,0,3],[2,4,3]]return = [true,false]

Peers 1 and 2 share manager 4. Person 3 instead has manager 0, so the final query is false.

Constraints

  • 1 <= personCount <= 100000.
  • 1 <= operations.length <= 100000.
  • Every operation has exactly three integers [type, a, b].
  • 0 <= type <= 2 and 0 <= a, b < personCount.
  • Type-0 and type-1 operations never contradict facts recorded earlier.
  • At least one operation is a query.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Radar Barrier CrossingSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions
  • Number of IslandsWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Number of IslandsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Number of Islands IIAmazon · ONSITE INTERVIEW
  • Find All People With SecretIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Group Linked Merchant RecordsStripe · PHONE SCREENStripe interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions

Interview reports that mention this question

  • Google Firmware New Grad Onsite Org-Chart Queries: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean[] answerManagerQueries(int personCount, int[][] operations) {
        // write your code here
    }
}
Checking account…