Question: Task 2 Java 8 There is a board made of two rows and N columns. The board is represented by two strings, row 1 and

Task 2
Java 8
There is a board made of two rows and N columns. The board is represented by two strings, row1 and row2, made of characters 'R','W' and/or '?'. A board is balanced if, in each row and in each column, the number of characters 'R' is equal to the number of characters 'W'. For example, the following board is balanced:
?RW?WR
?WR?RW
and the following board is not balanced:
W?WR?
R??W?
(there are two characters 'W' and one character 'R' in the first row).
The question marks ('?') can be replaced with 'W' or 'R'. What is the minimum number of replacements needed to balance the board?
Write a function:
class Solution { public int solution(String row1, String row2) ; }
that, given two strings row1 and row2 made of N characters each, returns the minimum number of replacements needed to balance the board. If it is not possible to balance the board, the function should return -1.
14C
Partly sunny
Search
 Task 2 Java 8 There is a board made of two

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!