FastPrepEarliest Full Connectivity with Edge Removals
Problems/Earliest Full Connectivity with Edge Removals

Earliest Full Connectivity with Edge Removals

Google logoGoogle● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the task and interview context. The callable signature, deterministic tie-breaking, examples, and bounds are source-faithful reconstruction details; estimated fidelity is 90%.

Process chronological logs [timestamp, operation, u, v] for an undirected social graph. Operation is ADD or REMOVE. All logs with the same timestamp take effect atomically.

Return the earliest timestamp after whose complete group all n users are connected. Duplicate additions and absent-edge removals are no-ops. Return -1 if this never occurs, and 0 for at most one user.

Function

firstFullyConnectedTimestamp(n: int, logs: String[][]) → long

Examples

Example 1

n = 4logs = [["1","ADD","0","1"],["2","ADD","2","3"],["3","ADD","1","2"]]return = 3

All four users first connect at timestamp 3.

Example 2

n = 3logs = [["1","ADD","0","1"],["2","ADD","1","2"],["2","REMOVE","0","1"]]return = -1

The atomic timestamp-2 state is disconnected.

Example 3

n = 1logs = []return = 0

One user is connected without an edge.

Constraints

  • 0 <= n <= 2000.
  • 0 <= logs.length <= 2000.
  • Logs are sorted by nondecreasing timestamp.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long firstFullyConnectedTimestamp(int n, String[][] logs) {
        // write your code here
    }
}
Checking account…