PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Count Overlapping Rectangle Updates on a Grid

Last updated: Jul 18, 2026

Quick Overview

Apply many inclusive rectangle increments to an n-by-n grid and return each cell's final coverage count. The constraints require handling up to one hundred thousand updates efficiently.

  • hard
  • Google
  • Coding & Algorithms
  • Software Engineer

Count Overlapping Rectangle Updates on a Grid

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

# Count Overlapping Rectangle Updates on a Grid Implement `range_add_counts(n, rectangles)`. Start with an `n x n` matrix of zeroes. Each rectangle is represented as `[row1, col1, row2, col2]` with inclusive, zero-based coordinates. For every rectangle, add one to each matrix cell inside that rectangle. Return the final matrix, where each cell therefore contains the number of input rectangles covering it. ## Example For `n = 3` and `rectangles = [[0, 0, 1, 1], [1, 1, 2, 2]]`, return: ```text [ [1, 1, 0], [1, 2, 1], [0, 1, 1] ] ``` ## Constraints - `1 <= n <= 500` - `0 <= len(rectangles) <= 100_000` - `0 <= row1 <= row2 < n` - `0 <= col1 <= col2 < n`

Quick Answer: Apply many inclusive rectangle increments to an n-by-n grid and return each cell's final coverage count. The constraints require handling up to one hundred thousand updates efficiently.

Related Interview Questions

  • Find A Threshold-Limited Path With Minimum Required Safety - Google (medium)
  • Filter Repeated Robot Status Messages - Google (medium)
  • Minimize Direction Violations in a Directed Road Network - Google (medium)
  • Find the Largest Monotone Increasing Number - Google (medium)
|Home/Coding & Algorithms/Google

Count Overlapping Rectangle Updates on a Grid

Google logo
Google
Jul 10, 2026, 12:00 AM
hardSoftware EngineerTechnical ScreenCoding & Algorithms
9
0
PracticeRead

Count Overlapping Rectangle Updates on a Grid

Implement range_add_counts(n, rectangles).

Start with an n x n matrix of zeroes. Each rectangle is represented as [row1, col1, row2, col2] with inclusive, zero-based coordinates. For every rectangle, add one to each matrix cell inside that rectangle. Return the final matrix, where each cell therefore contains the number of input rectangles covering it.

Example

For n = 3 and rectangles = [[0, 0, 1, 1], [1, 1, 2, 2]], return:

[
  [1, 1, 0],
  [1, 2, 1],
  [0, 1, 1]
]

Constraints

  • 1 <= n <= 500
  • 0 <= len(rectangles) <= 100_000
  • 0 <= row1 <= row2 < n
  • 0 <= col1 <= col2 < n

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.