FastPrepBlocking Connection Pool Operation Trace
Problems/Blocking Connection Pool Operation Trace

Blocking Connection Pool Operation Trace

Google logoGoogle● HardINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the connection-pool methods, the blocking behavior, the concurrency needs, a guard against releasing a connection twice, suggested tools, and a follow-up on preventing leaks. It does not give a fixed trace of operations or input limits. We added both. Our version is about 89% the same as the reported question.

Simulate the observable behavior of a blocking database connection pool over a finite operation trace.

The pool is initialized with maxSize independent connections numbered 0 through maxSize - 1. All connections begin idle, in a queue ordered by increasing ID. Take idle connections from the front of this queue. Each row operations[i] = [type, value] is processed in input order:

  • type = 0 is GET for the unique request ID value. If an idle connection exists, remove the FIFO head, mark it active, and emit [i, 0, value, connectionId]. Otherwise the call waits in a queue, in request order. It emits nothing until a later valid release gives it a connection.
  • type = 1 is RELEASE for connection ID value. Emit [i, 1, value, success], where success is 1 only when that connection is currently active. A failed or repeated release changes nothing. After a successful release, transfer the connection directly to the oldest blocked GET, if one exists, and then emit that request's assignment event. Otherwise append the connection to the idle FIFO queue.
  • type = 2 is ACTIVE_COUNT; ignore value and emit [i, 2, activeCount, 0].

Return events in the order they are emitted. A GET still blocked after the final operation never completes and produces no event. Return the complete event list as an int[][].

Interview extensions

  • Describe a real thread-safe implementation using a semaphore, a blocking queue, and ownership tracking.
  • Explain how to prevent or recover leaked connections with bounded leases, health checks, and observability.

Function

simulateConnectionPool(maxSize: int, operations: int[][]) → int[][]

Examples

Example 1

maxSize = 2operations = [[0,101],[0,102],[2,0],[0,103],[1,0],[2,0],[1,0],[1,1],[2,0]]return = [[0,0,101,0],[1,0,102,1],[2,2,2,0],[4,1,0,1],[3,0,103,0],[5,2,2,0],[6,1,0,1],[7,1,1,1],[8,2,0,0]]

Requests 101 and 102 receive both connections. Request 103 blocks. Releasing connection 0 emits the release result and then completes request 103 with that same connection.

Example 2

maxSize = 1operations = [[0,7],[1,0],[1,0],[2,0]]return = [[0,0,7,0],[1,1,0,1],[2,1,0,0],[3,2,0,0]]

The first release succeeds. The repeated release is rejected and does not change the active count.

Example 3

maxSize = 1operations = [[0,10],[0,20],[0,30],[1,0],[1,0],[2,0]]return = [[0,0,10,0],[3,1,0,1],[1,0,20,0],[4,1,0,1],[2,0,30,0],[5,2,1,0]]

Requests 20 and 30 wait in FIFO order. Each successful release transfers connection 0 directly to the oldest waiter.

Example 4

maxSize = 1operations = [[0,1],[0,2],[2,0]]return = [[0,0,1,0],[2,2,1,0]]

Request 2 remains blocked when the trace ends, so it has no completion event.

Constraints

  • 1 <= maxSize <= 100000
  • 1 <= operations.length <= 200000
  • Each operations[i] contains exactly two integers.
  • 0 <= type <= 2
  • Every GET request ID is positive and unique.
  • A RELEASE value may be any signed 32-bit integer; it succeeds only for a currently active connection ID.
  • The number of emitted events fits in memory.

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

  • Durable Work Queue OperationsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Matching Engine with Order CancellationIMC Trading · ONSITE INTERVIEWIMC Trading interview questions
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Concurrent Buffered File LoggerDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Article Vote TrackerRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Dynamic Least-Loaded Job DispatcherCresta · PHONE SCREENCresta interview questions
  • Single-Flight Chunk CacheModal · PHONE SCREEN

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
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] simulateConnectionPool(int maxSize, int[][] operations) {
      // Write your code here.
    }

}
Checking account…