FastPrepDynamic Island Counts
Problems/Dynamic Island Counts

Dynamic Island Counts

Uber logoUber● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report explicitly names the incremental island-counting follow-up. Repeated additions and bounded integer-grid inputs are conventional deterministic practice details; the judged core task matches at about 98%.

An initially all-water grid has rows rows and cols columns. Process the positions in order. For each [row, col], turn that cell into land if it is still water, then record the current number of horizontally or vertically connected islands.

If a position is repeated, the grid does not change and the previous island count is recorded again. Return one count per position.

Function

dynamicIslandCounts(rows: int, cols: int, positions: int[][]) → int[]

Examples

Example 1

rows = 3cols = 3positions = [[0,0],[0,1],[1,2],[2,1]]return = [1,1,2,3]

The second addition joins the first island; the final two additions are isolated from existing land.

Example 2

rows = 3cols = 3positions = [[0,0],[0,1],[1,2],[1,1]]return = [1,1,2,1]

The last cell bridges the two existing islands into one.

Example 3

rows = 1cols = 2positions = [[0,0],[0,0],[0,1]]return = [1,1,1]

The repeated position is a no-op, and the final cell joins the existing island.

Constraints

  • 1 <= rows, cols <= 10000.
  • 1 <= positions.length <= 100000.
  • Every position contains exactly two integers within the grid.
  • rows * cols <= 10^7.

More Uber problems

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int[] dynamicIslandCounts(int rows, int cols, int[][] positions) {
        // Write your solution here.
    }
}
Checking account…