As reported: Uber L4 online assessment (2025), 4 questions in 90 minutes; the hard one: given
rowsandcols(each up to10^5) and the list of cells that hold1(all others0), return a vector of length 5 whosei-th entry is the number of 2×2 submatrices containing exactlyiones. Checking every 2×2 submatrix times out.
A rows × cols grid is all 0 except the cells listed in ones (ones[j] = [r, c], 0-based, distinct), which hold 1. Return answer of length 5, where answer[i] is the number of 2×2 submatrices (contiguous blocks of 2 rows × 2 columns) containing exactly i ones.
Example
rows = 3, cols = 3, ones = [[0,0],[0,1],[1,1]]
Output: [0,2,1,1,0]
The four 2×2 blocks (by top-left corner): (0,0) has 3 ones, (0,1) has 2, (1,0) has 1, (1,1) has 1.
Constraints: 2 ≤ rows, cols ≤ 10^5; 0 ≤ ones.length ≤ 10^5. answer[0] can reach about 10^10 — use 64-bit integers.
Code runner format: one JSON value per line: rows, cols, ones. Implement countBlocks(rows, cols, ones); the harness prints the 5 counts.