Description
Solutions
Submission
Flower Bouquets 💐
🤘 INTERN

A flower shop has only two types of flower bouquets:

  • Type 1: This contains three roses and costs p dollars.
  • Type 2: This contains one cosmos and one rose and costs q dollars.
  • The flowers are grown in a single row. Consider the row as a one-dimensional array where each cell either contains a rose or a cosmos. For example, the image is based on the array 001101011, here 0 indicates rose, and 1 indicates cosmos.

    Any bouquet must be formed from consecutive flowers. For example, in a bouquet, the flower from consecutive indices (i, i+1, and i+2) in the array can be present, but not from non-consecutive indices (i and i+2). In the array shown, there are no bouquets of type 1, but 3 bouquets of type 2 can be created.

    Given a binary string representing the garden row, determine the maximum revenue possible. It is not necessary to use every flower.

    Function Description

    Complete the function flowerBouquets in the editor.

    flowerBouquets has three parameters:

    1. int p: the cost of a type 1 bouquet
    2. int q: the cost of a type 2 bouquet
    3. string s: the garden pattern as a binary string where 0 indicates rose and 1 indicates cosmos

    Returns

    int: the maximum value of flower bouquets

    Example 1:

    Input:  p = 2, q = 3, s = "0001000"
    Output: 5
    Explanation:
    There are two bouquets of three roses (Type 1) at indices (0, 1, 2), and (4, 5, 6) that sell for 2+2 = 4. There is one Type 1 bouquet (0, 1, 2) and one Type 2 bouquet at (3, 4). They sell for 2+3 = 5.
    Constraints:
      • 1 ≤ p, q ≤ 1000
      • 1 ≤ |s| ≤ 100000
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: