Normalize Columns in Binomial Matrix Efficiently
Company: Google
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in matrix manipulation, handling of binomial random samples, column normalization, and algorithmic efficiency for processing large numerical arrays.
Constraints
- 1 <= n, m <= 1000
- matrix is rectangular with all rows of equal length
- Each entry matrix[i][j] is 0 or 1
- Return a new matrix of floats
- Time complexity should be O(n*m) (O(n^2) for square matrices)
- If a column sum is 0, the entire column remains zeros
Hints
- Compute all column sums in a single pass over the matrix.
- Then divide entries by their column sum to fill the output.
- If a column sum is zero, skip dividing that column to avoid division by zero.
- Avoid recomputing column sums per row or per element.