subject
Mathematics, 30.07.2021 04:30 hailiemanuel9362

There is a road consisting of N segments, numbered from 0 to N-1, 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: class Solution { public int solution(String S); } that, given a string S of length N, returns the minimum number of patches required to repair all the potholes. Examples: 1. Given S=".X..X", your function should return 2. The road fixing machine could patch, for example, segments 0-2 and 2-4.
2. Given S = "x..x", your function should return 3The road fixing machine could patch, for example, segments 0-2, 3-5 and 6-8.
3. Given S = "xx. xxx", your function should return 2. The road fixing machine could patch, for example, segments 0-2 and 3-5.
4. Given S = "", your function should return 2. The road fixing machine could patch, for example, segments 0-2 and 1-3. Write an efficient algorithm for the following assumptions:
N is an integer within the range [3..100,000);
string S consists only of the characters"." and/or "X".

ansver
Answers: 3

Other questions on the subject: Mathematics

image
Mathematics, 21.06.2019 19:30, vtrvfrfvrvfvnkjrf
What is the slope of the line shown below?
Answers: 2
image
Mathematics, 21.06.2019 23:00, jnsoccerboy7260
The perimeter of a rectangular rug is 24 feet. the length of the rug is 1 2/5 i s width. what is the area of the rug
Answers: 2
image
Mathematics, 21.06.2019 23:10, robert7248
Aline has a slope of . which ordered pairs could be points on a parallel line? check all that apply. (-8, 8) and (2, 2) (-5, -1) and (0, 2) (-3, 6) and (6, -9) (-2, 1) and (3,-2) (0, 2) and (5,5)
Answers: 3
image
Mathematics, 21.06.2019 23:20, emilypzamora11
Find the common ratio of the sequence. -4, 8, -16, 32, a: -12b: -2c: 12d: -1/-2
Answers: 1
You know the right answer?
There is a road consisting of N segments, numbered from 0 to N-1, represented by a string S. Segment...

Questions in other subjects:

Konu
Mathematics, 07.04.2021 21:10
Konu
Computers and Technology, 07.04.2021 21:10
Konu
Mathematics, 07.04.2021 21:10
Konu
History, 07.04.2021 21:10