Flower Bouquets π
Updated
Problem statement
A flower shop has only two types of flower bouquets:
p dollars.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
flowerBouquets(p: int, q: int, s: String) β int
Complete the function flowerBouquets in the editor.
flowerBouquets has three parameters:
int p: the cost of a type 1 bouquetint q: the cost of a type 2 bouquetstring s: the garden pattern as a binary string where0indicates rose and1indicates cosmos
Returns
int: the maximum value of flower bouquets
Examples
Example 1
p = 2q = 3s = "0001000"return = 5Constraints
1 β€ p, q β€ 10001 β€ |s| β€ 100000
More Atlassian interview questions
- Merge Overlapping IntervalsPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Tennis Court SchedulingPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Deterministic Word Guess SolverONSITE INTERVIEW Β· Seen Oct 2026
- Generate Word Guess FeedbackONSITE INTERVIEW Β· Seen Oct 2026
- Bounded Word Guess SolverONSITE INTERVIEW Β· Seen Oct 2026
- Implement a Rate LimiterPHONE SCREEN Β· Seen Oct 2026
- Word Guess Feedback ColorsONSITE INTERVIEW Β· Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN Β· Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN Β· Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN Β· Seen Aug 2026
Similar questions at other companies
- Maximum Equal-Bit Pairs in a SubsequenceAmazon Β· OA
- Longest Subsequence That Is a SubstringBooking.com Β· OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft Β· OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs Β· OAGoldman Sachs interview questions
- Longest String ChainVisa Β· OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai Β· OA
- Maximum Redundancy After One Segment FlipBloomberg LP Β· OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe Β· OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget Β· OA
- Longest Subsequence That Is a SubstringWells Fargo Β· OAWells Fargo interview questions