code in cpp Revisit Later Black and White Walls There are N black and white colored…
- User
code in cpp Revisit Later Black and White Walls There are N black and white colored walls (1 <= N <=89). You are given a string array named Colors, where each element of the array is either "White" or "Black", representing the initial color of the walls. By choosing a Black wall and a White wall, you can swap their colors at some cost. You can do this swapping any number of times. The cost of swapping colors of an ith (1 <= <N) White colored wall with a jth (1 <= j <=N) Black colored wall is calculated as li از Your task is to find and return the minimum cost to be incurred for changing the initially Black colored walls to White colored walls using the method mentioned above. Note: • Initially, the total number of Black walls is not greater than half of the total number of walls • Consider 1-based indexing. Input Specification: input1: An integer value N representing the number of walls. input2: A string array Colors, where each element of the array is either "White" or "Black", representing the initial color of the wall.Example 1: input1:6 input2: (Black, Black, Black, White, White White) Output: 9 Explanation: • Choose the first and fourth index walls and swap their colors. The cost will be 11 413 and the Colors array will now become (White Black, Black, Black, White, White). • Now choose the second and sixth index walls and swap their colors. The cost will be 12-614 and the Colors array will now become (White, White, Black, Black, White Black). • Now choose the third and fifth index walls and swap their colors. The cost will be 13512 and the Colors array will now become (White, White White Black, Black, Black). The final cost will be 7 + 2 = 9. As 9 is the minimum cost to be incurred to make all the initially black colored walls white, 9 is returned as the output. Example 2: input1:3 input2: (White, White, White)
- Assistant