Minimum Replacements Required to Make a Matrix Balanced
See Microsoft hiring insights
Given a 2D matrix with 2 rows and columns, containing only the characters
'R', 'W', '?', give the minimum replacements of
'?' required to make the matrix balanced.
The matrix would be balanced when it has equal number of 'W' and 'R'
in all the rows and columns.
E.g. - R1 - "WR???"; R2 - "R???W" - Balanced - R1 - "WR?W",
R2 - "RW?W"; 4 replacements
matrix = [['W', 'R', '?', '?', '?'], ['R', '?','?', '?', 'W']] return = 4
The given matrix can be balanced by making the following replacements:
Replace the first '?' in R1 with 'W' and the second '?' with 'R'.
Replace the first '?' in R2 with 'W' and the second '?' with 'R'.
This results in 4 replacements, making the matrix balanced with equal numbers of 'W' and 'R' in all rows and columns.
Standard Huge Constraints- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Get Minimum TimeSeen Jun 2025
- Count Subarrays with Bitwise OR PresentSeen Jun 2025
- Get Max Or SumSeen Jun 2025
public int minimumReplacementsRequired(char[][] matrix) {
// write your code here
}