PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in matrix manipulation, handling of binomial random samples, column normalization, and algorithmic efficiency for processing large numerical arrays.

  • Medium
  • Google
  • Coding & Algorithms
  • Data Scientist

Normalize Columns in Binomial Matrix Efficiently

Company: Google

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Scenario Write code that creates a 100×100 matrix of Binomial(1, 0. 5) samples and normalizes each column so it sums to 1. ##### Question Provide an efficient algorithm (language of your choice) to perform the above task in O(n²) time. ##### Hints Vectorized NumPy operations beat nested loops.

Quick Answer: This question evaluates proficiency in matrix manipulation, handling of binomial random samples, column normalization, and algorithmic efficiency for processing large numerical arrays.

Given an n x m binary matrix (entries are 0 or 1), return a new matrix of floats where each column is normalized to sum to 1. For each column j with sum s > 0, set output[i][j] = matrix[i][j] / s for all rows i. If a column sum is 0, leave that column as all zeros. Preserve the original shape and row/column order.

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

  1. Compute all column sums in a single pass over the matrix.
  2. Then divide entries by their column sum to fill the output.
  3. If a column sum is zero, skip dividing that column to avoid division by zero.
  4. Avoid recomputing column sums per row or per element.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Infection Spread on a Grid (Cellular Automaton) - Google (hard)
  • Most Active Users in a Live Communication Stream - Google (medium)
  • Boolean Expression Tree with Leaf Flips - Google (medium)
  • Streaming Points: Remove Any Pair Within a Distance - Google (medium)
  • Solve Rooms and Top-K Streams - Google (medium)