Matrix Region Sum
Updated
Problem statement
Given an integer matrix matrix and a non-negative region radius r, construct an output matrix of the same size.
For each cell (row, col), sum every input cell (i, j) satisfying:
row - r <= i <= row + r
col - r <= j <= col + rOnly coordinates inside the matrix are included. The center cell is included in its own sum.
Function
matrixRegionSum(matrix: int[][], r: int) → int[][]Examples
Example 1
matrix = [[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]r = 1return = [[4,6,6,6,4],[6,9,9,9,6],[6,9,9,9,6],[4,6,6,6,4]]Moved or new
The top-left cell sees the clipped 2 x 2 region and has sum 4. Interior cells see a full 3 x 3 region and have sum 9.
Example 2
matrix = [[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]r = 2return = [[9,12,15,12,9],[12,16,20,16,12],[12,16,20,16,12],[9,12,15,12,9]]Moved or new
With radius 2, the center columns include all five input columns while edge cells use clipped regions.
Constraints
1 <= matrix.length, matrix[0].length <= 10000 <= r <= 1000- All output sums fit in a signed 32-bit integer.
More Rippling Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- Cyber Beacon DetectionOA · Seen Aug 2026
Similar questions at other companies
- Leaves Remaining After Wind GustsOpenAI · OAOpenAI interview questions
- Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
- Centered K-by-K Submatrix SumsCitadel · ONSITE INTERVIEWCitadel interview questions
- Inclusive Rectangle Coverage CountsGoogle · ONSITE INTERVIEWGoogle interview questions
- Sub-matrix SumsIMC Trading · OAIMC Trading interview questions
- Restaurant Delivery HeatmapDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Alien Defense Turret PlacementBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Largest Sub-GridMathWorks · OAMathWorks interview questions
- Maximum Trailing Zeros on a Path with at Most One TurnMarshall Wace · OAMarshall Wace interview questions
- Square-Neighborhood Image BlurZipRecruiter · OAZipRecruiter interview questions
Interview reports that mention this question
Rippling interview experiences
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
- Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)