FastPrepDynamic Friendship Connectivity
Problems/Dynamic Friendship Connectivity

Dynamic Friendship Connectivity

Google logoGoogle● HardNEW GRADINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One interview report describes adding, deleting, and querying undirected server connections. It includes parallel connections, deleting one copy, queries about the same server, and tradeoffs between workloads with many changes and many queries. An earlier report describes the same fully dynamic friendship-connectivity problem and points to rollback union-find. We chose the numeric operation codes, the finite limits, and returning the answers as a batch.

There are n servers numbered from 0 through n - 1. Initially, there are no connections. Connections work in both directions, and there may be more than one connection between the same two servers. Process operations in order:

  • [0, u, v] adds one connection between u and v. Parallel connections are allowed.
  • [1, u, v] removes one existing connection between u and v. Other parallel connections remain active.
  • [2, u, v] asks whether u and v are connected by a path along which at least one connection remains between each neighboring pair.

Return the answers to all query operations in their original order. A server is connected to itself, so every query with u == v returns true.

Function

dynamicFriendshipConnectivity(n: int, operations: int[][]) → boolean[]

Examples

Example 1

n = 4operations = [[0,0,1],[0,1,2],[2,0,2],[1,1,2],[2,0,2]]return = [true,false]

The first two connections link servers 0 and 2. Removing {1,2} breaks that path before the second query.

Example 2

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

Two parallel connections join 0 and 1. Removing one occurrence leaves the other active; removing the second disconnects them. Server 2 is always connected to itself.

Example 3

n = 4operations = [[0,0,1],[0,1,2],[0,0,2],[2,0,2],[1,0,2],[2,0,2],[1,1,2],[2,0,2]]return = [true,true,false]

After the direct edge {0,2} is removed, the path through server 1 still connects the endpoints. Removing {1,2} then breaks the last path.

Constraints

  • 1 <= n <= 100000.
  • 1 <= operations.length <= 100000, and at least one operation is a query.
  • operations[i].length == 3.
  • operations[i][0] is 0, 1, or 2.
  • 0 <= operations[i][1], operations[i][2] < n.
  • Addition and removal endpoints are distinct.
  • Every removal has at least one matching active connection occurrence.

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

  • Count Islands from Streaming RowsAmazon · ONSITE INTERVIEW
  • Find All People With SecretIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Maximum Edge Removals for Two TravelersMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • Making a Large IslandMeta · ONSITE INTERVIEWMeta interview questions
  • Largest Island After One Land ConversionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Water Supply With Wells and PipesNutanix · ONSITE INTERVIEWNutanix interview questions
  • Evaluate DivisionPlaud · ONSITE INTERVIEW
  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Radar Barrier CrossingSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Accounts MergeOracle · ONSITE INTERVIEWOracle interview questions

Interview reports that mention this question

  • Google New Grad Onsite Filesystem and Connectivity: 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[] dynamicFriendshipConnectivity(int n, int[][] operations) {
        // write your code here
    }
}
Checking account…