Distinct Values on Maximum-Sum Frames
Updated
Problem statement
Given an integer matrix and frameSize, consider every contiguous frameSize × frameSize submatrix. Its border contains each cell on its top row, bottom row, left column, or right column exactly once.
Find the maximum border sum. Among every frame tied for that maximum, collect all integer values that occur on a winning border. Return the sum of those distinct values.
Function
sumDistinctWinningBorderValues(matrix: int[][], frameSize: int) → longExamples
Example 1
matrix = [[1,2,3],[4,5,6],[7,8,9]]frameSize = 2return = 28The bottom-right 2-by-2 frame has the unique maximum border sum, and 5+6+8+9=28.
Example 2
matrix = [[1,1,1],[1,0,1],[1,1,1]]frameSize = 2return = 1All four frames tie; the union of their border values is {0,1}.
Constraints
1 <= rows, columns <= 200.1 <= frameSize <= min(rows, columns).- Matrix values fit in a 32-bit signed integer; the result fits in a 64-bit signed integer.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Distinct Values on Maximum-Sum FramesCapital One · OACapital One interview questions
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
- Four-by-Four Boundary GridSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Center of the Largest Perfect X-ShapeTikTok · OATikTok interview questions
- Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Shortest Path in a Binary MatrixGoogle · OAGoogle interview questions
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Grid Paths with Override PassesIMC Trading · OAIMC Trading interview questions
- Minimum MovesHarness · OA