Minimum Number of Buckets Required to Collect Rainwater from Houses LeetCode solution in C++
1class Solution {2public:3int minimumBuckets(string street) {4unordered_map<int, int> mp;5int res = 0;6for (int i = 0; i < street.size(); i++) {7if (street[i] == 'H') {8if (mp[i + 1] > 0 or mp[i - 1] > 0) continue;9if (i + 1 < street.size() and street[i + 1] == '.') {10res++;11mp[i + 1]++;12continue;13}14if (i - 1 >= 0 and street[i - 1] == '.') {15res++;16continue;17}18return -1;19}20}21return res;22}23};