Using 2 stacks to mimic the 2 bucket, suppose s1 has 5L and s2 has 3L. Algorithm: 1) Fill s1 to be full 2) Move the water in s1 to s2 until s2 is full 3) Empty s2 4) Move the water in s1 to s2 until s1 is empty 5) Fill s1 to be full 6) Move the water in s1 to s2 until s2 is full Code: #include using namespace std; const int kSize1 = 5; const int kSize2 = 3; void PourWater(stack &s1, stack &s2) { for (int i = 0; i < kSize1; i++) { s1.push(1); } for (int i = 0; i < kSize2; i++) { int temp = s1.top(); s1.pop(); s2.push(temp); } while (!s2.empty()) { s2.pop(); } while (!s1.empty()) { int temp = s1.top(); s1.pop(); s2.push(temp); } for (int i = 0; i < kSize1; i++) { s1.push(1); } while (s2.size() != kSize2) { int temp = s1.top(); s1.pop(); s2.push(temp); } }