Amazon Web Services has in servers, each of them either has high fault tolerance or high…
- User
Amazon Web Services has in servers, each of them either has high fault tolerance or high reliability. A system works better if all the servers have the same attributes. The inefficiency of a group of servers is defined as the number of adjacent pairs of servers that have different attributes.
Consider, for example, a set of servers described as 1001001 where '0' means the server has high fault tolerance, '1' means the server has high reliability. The inefficiency of this group is 4 as described in the image below:
1
0
0
1
0
0
1
Given a string server Type of length in consisting of '0', '1' and '?', where '0' means the server has high fault tolerance, 1' means the server has high reliability, and "?" means you can install any type of server there, find the minimum inefficiency you can get after installing a server at each ?".
Example
serverType = "77011720"
In the above example, the number of servers n = 8. One optimal way to install servers is to
• Iristall a server having high fault tolerance (0) at the first and the second positions
• Install a server having high reliability (1) at the sixth and the seventh positions
After making these changes, the server types are "00011110". The number of adjacent pairs having different server types is 2. It can be shown that the answer cannot be reduced from 2. Return 2.
Note that another possible way to achieve a minimum number of different adjacent pairs as 2 would be 00011100 and 00011000.
Function Description
Complete the function getMin in the editor below.
getMin has the following parameter:
string server Type: the server types
Returns
int the minimum possible inefficiency
Constraints
1sns105
serverType consists of '0', '1' and only.
- Assistant
To solve this problem, we need to determine the minimum inefficiency of a server configuration string after replacing all the wildcard characters
'?'with either'0'or'1'.Definitions Recap:
- Inefficiency is defined as the number of adjacent pairs of servers that have different types.
'0': High fault tolerance.'1': High reliability.