435. Maximum Number of Potholes That Can Be Fixed

Given an integer budget and a string road, consisting only of characters 'x' and '.', where 'x' represents a pothole and '.' represents a smooth road. In one repair operation, you can fix n consecutive potholes for a cost of n + 1. Return the maximum number of potholes that can be fixed such that the sum of all repair costs does not exceed the given budget.

Example 1:

Input: road = "....", budget = 3

Output: 0

Explanation: There are no potholes to fix.

Example 2:

Input: road = "x.xx....xx", budget = 6

Output: 4

Explanation:

We can fix two separate pothole groups:

Fix 'x' (cost 1 + 1 = 2).

Fix 'xx' (cost 2 + 1 = 3).

Total cost: 2 + 3 = 5 (within budget).

Now Your Turn!

Pick the correct output for the given input

Input: road = "xxx..x.x.xx", budget = 10

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= road.length <= 105
  • 1 <= budget <= 105 + 1
  • road consists only of '.' and 'x'.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int maxPotholes(string road, int budget) {
}
};
Test Case

Input:

Budget
Road