Question: using python There is a road consisting of N segments, numbered from 0 to N1, represented by a string S. Segment S[K] of the road
There is a road consisting of N segments, numbered from 0 to N1, represented by a string S. Segment S[K] of the road may contain a pothole, denoted by a single uppercase " x " character, or may be a good segment without any potholes, denoted by a single dot, " . For example, string " .x..x means that there are two potholes in total in the road: one is located in segment S[1] and one in segment S[4]. All other segments are good. The road fixing machine can patch over three consecutive segments at once with asphalt and repair all the potholes located within each of these segments. Good or already repaired segments remain good after patching them. Your task is to compute the minimum number of patches required to repair all the potholes in the road. Write a function: def solution(5) that, given a string S of length N, returns the minimum number of patches required to repalr all the potholes. Examples: 1. Glven S=,x.,X, your function should retum 2. The road fixing machine could patch, for example, segments 02 and 24. 2. Given S=x.x000x.x." your function should return 3. The road fixing machine could patch, for example, segments 02,35 and 68. 3. Given S="xx,x00..: your function should return 2. The road fixing machine could patch, for example, segments 02 and 35. 4. Given S= " "oocx", your function should return 2. The road fixing machine could patch, for example, segments 0-2 and 1-3. Write an efficlent algorithm for the following assumptions: - Nis an integer within the range [3.100,000]; - string S is made only of the characters ". "and/or " x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
