Fix max potholes
You are given a description of a two-lane road in which two strings, L1
and L2
, respectively represent the first and the second lane, each lane consisting of N
segments of equal length.
The K-th segment of the first lane is represented by L1[K]
and the K-th segment of the second lane is represented by L2[K]
, where '.'
denotes a smooth segment of road and 'x'
denotes a segment containing potholes.
Cars can drive over segments with potholes, but it is rather uncomfortable. Therefore, a project to repair as many potholes as possible was submitted. At most one contiguous stretch of each lane may be repaired at a time. For the time of reparation, those stretches will be closed to traffic.
How many road segments with potholes can be repaired given that the road must be kept open (in other words, stretches of roadworks must not prevent travel from one end of the road to the other)?
Given two strings L1
and L2
of length N
, return the maximum number of segments with potholes that can be repaired.
Constraints
N
is an integer within the range[1..200,000]
.Strings
L1
andL2
consist only of the characters'.'
and'x'
.
Examples
Input:
Output:
4
Explanation: It is possible to repair three potholes in the first lane and the first pothole in the second lane without closing the road to traffic.Input:
Output:
6
Input:
Output:
5
Input:
Output:
2
Answer
Last updated