FastPrepFinal Task From Unordered Server-Split Logs
Problems/Final Task From Unordered Server-Split Logs

Final Task From Unordered Server-Split Logs

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the server process that splits work in half, the four-task example, logs in any order, the rule that the count is a power of two, and the parent and outdegree recurrence. We fixed what inputs are guaranteed valid and what the function returns. Our version is about 96% the same as the reported question.

There are serverCount tasks numbered from 0 to serverCount - 1. Initially server 0 stores all tasks in order and every other server is empty.

A transfer [from,to] moves the last half of from's current block of consecutive tasks to the empty server to, preserving order. Transfers continue until every server stores one task. You receive all transfers in arbitrary order.

The input is guaranteed to describe one valid complete split process, and serverCount is a power of two. Return the final task number stored on serverId.

Function

finalTaskForServer(serverCount: int, transfers: int[][], serverId: int) → int

Examples

Example 1

serverCount = 4transfers = [[0,2],[2,1],[0,3]]serverId = 1return = 3

The process ends with servers 0,3,2,1 holding tasks 0,1,2,3, respectively.

Example 2

serverCount = 4transfers = [[2,1],[0,3],[0,2]]serverId = 2return = 2

Log order does not matter. Server 2 retains task 2.

Example 3

serverCount = 8transfers = [[4,5],[0,1],[2,3],[0,4],[6,7],[0,2],[4,6]]serverId = 7return = 7

The parent chain 0 → 4 → 6 → 7 contributes block offsets 4 + 2 + 1.

Constraints

  • 2 <= serverCount <= 1048576 and it is a power of two.
  • transfers.length == serverCount - 1.
  • Every transfer contains two distinct server IDs in [0,serverCount-1].
  • The transfers form a valid complete process rooted at server 0.
  • 0 <= serverId < serverCount.

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

  • Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
  • Minimum Operations with Multiply by Two and Divide by ThreeBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
  • Path Between Two Nodes of a Fibonacci TreeDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Delete and Compact a Forest SubtreePinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions
  • Top-Down Employee Reporting ForestOkta · ONSITE INTERVIEWOkta interview questions
  • Distance Between Two Tree NodesAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Aggregate Machine TopologyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Binary Tree Nodes at Distance KApple · ONSITE INTERVIEWApple interview questions

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 finalTaskForServer(int serverCount, int[][] transfers, int serverId) {
        // Write your code here.
    }
}
Checking account…