Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Food Buckets to Feed the Hamsters

med
30 min
Try to solve the Minimum Number of Food Buckets to Feed the Hamsters problem.

Statement

You are given a 00 indexed string hamsters where each character represents a position in a line:

  • 'H' represents a hamster.

  • '.' represents an empty space.

You may place food buckets on empty positions. A hamster situated at index i is fed if there is a food bucket placed at index i−1i - 1 or index i+1i + 1. A single food bucket placed at an empty space can feed hamsters on both its adjacent sides.

Return the minimum number of food buckets needed to feed all the hamsters, or −1-1 if it is impossible to feed every hamster.

Constraints:

  • 1≤1 \leq hamsters.length ≤105\leq 10^5

  • hamsters[i] is either 'H' or '.'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Food Buckets to Feed the Hamsters

med
30 min
Try to solve the Minimum Number of Food Buckets to Feed the Hamsters problem.

Statement

You are given a 00 indexed string hamsters where each character represents a position in a line:

  • 'H' represents a hamster.

  • '.' represents an empty space.

You may place food buckets on empty positions. A hamster situated at index i is fed if there is a food bucket placed at index i−1i - 1 or index i+1i + 1. A single food bucket placed at an empty space can feed hamsters on both its adjacent sides.

Return the minimum number of food buckets needed to feed all the hamsters, or −1-1 if it is impossible to feed every hamster.

Constraints:

  • 1≤1 \leq hamsters.length ≤105\leq 10^5

  • hamsters[i] is either 'H' or '.'.