You're managing a hamster habitat represented by a string where each position can either contain a hamster ('H') or be empty ('.'). Your goal is to strategically place food buckets in empty positions to feed all the hamsters using the minimum number of buckets possible.
A hamster can be fed if there's at least one food bucket in an adjacent position (either immediately to its left or right). For example, if there's a hamster at position i, placing a food bucket at position i-1 or i+1 will satisfy that hamster's needs.
The Challenge: Find the minimum number of food buckets needed to feed all hamsters, or return -1 if it's impossible to feed them all.
Examples:
• "H.H" → Need 1 bucket in the middle: "HFH"
• "HHH" → Impossible! Adjacent hamsters can't share food buckets
• "H..H" → Need 2 buckets: "HF.FH" or optimize to 1: "H.FH"
Input & Output
Constraints
- 1 ≤ hamsters.length ≤ 105
- hamsters[i] is either 'H' or '.'
- Each hamster must be fed by at least one adjacent bucket
- Food buckets can only be placed in empty positions ('.')