Get Maximum Greyness π
Learn this problemProblem statement
Several satellites provide observational black and white images which are stored in data centers at Amazon Web Services (AWS).
A black and white image is composed of pixels and is represented as an n x m grid of cells. Each cell has a value of 0 or 1, where 0 represents a white pixel and 1 represents a black pixel. The grayness of a cell (i, j) is affected by the pixel values in the ith row and the jth column. More formally, the grayness of the cell (i, j) is the difference between the number of black pixels in the ith row and the jth column and the number of white pixels in the ith row and the jth column.
Find the maximum grayness among all the cells of the grid.
Note: The value of cell (i, j) is counted both in the ith row and in the jth column.
Function
getMaxGrayness(pixels: String[]) β int
Complete the function getMaximumGreyness in the editor.
GetMaximumGreyness has the following parameter:
string pixels[n]: a grid of pixels, where the ithstring consists of m characters and represents the ithrow of pixels.Returns
int: the max greyness of the grid of pixels.*** π Credit to kcho π ***
Examples
Example 1
pixels = ["1010", "0101", "1010"]return = 1n x m = 3 x 4 grid of pixels looks like this:
1 0 1 00 1 0 1
1 0 1 0 The grayness of each cell is: 1 -1 1 -1
1 -1 1 -1
1 -1 1 -1 The maximum achievable grayness is 1.
Example 2
pixels = ["011", "101", "001"]return = 43 x 3 grid of pixels looks like this:
0 1 11 0 1
0 0 1 The grayness of each cell is: 0 0 4
0 0 4
-2 -2 2 The maximum achievable grayness is 4.
Example 3
pixels = ["101", "001", "110"]return = 2
3 x 3 grid of pixels looks like this:
1 0 10 0 1
1 1 0 The greyness of the cell (1, 1) is calculated as the image above π The greyness of each cell is: 2 0 2
0 -2 0
2 0 2 The maximum achievable greyness is 2.
Constraints
1 β€ n, m β€ 1000pixels[i][j] = '0'or'1'for all0 β€ i < nand0 β€ j < m
More Amazon problems
- Drone Delivery RouteOA Β· Seen Aug 2026
- Package Dependency OrderPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Aug 2026
- Unfulfilled Customers by Inventory PriorityOA Β· Seen Aug 2026
- Calculate Beauty ValuesOA Β· Seen Aug 2026
- Maximize Distance to the Closest Occupied SeatONSITE INTERVIEW Β· Seen Aug 2026
- Package Delivery SystemOA Β· Seen Aug 2026
- Select Least Resource TasksOA Β· Seen Aug 2026
- Maximum Length-K Window Sum over Sparse SegmentsOA Β· Seen Aug 2026