Candies are stored in a list in their packing order. Each value represents the flavor of one candy.
Find every consecutive batch containing at least three candies of the same flavor.
CandyBatchAnalyzer
List<String> findRepeatedBatches( List<String> candyFlavors )
candyFlavors: The flavors of the candies in their packing order.Return one string for each repeated batch in the format "startIndex,endIndex".
Both indices are inclusive. Return the batches in increasing order of their starting indices.
Return an empty list if there are no repeated batches.
0.1 ≤ candyFlavors.size() ≤ 1,0001 ≤ candyFlavors.get(i).length() ≤ 20candyFlavors is null. findRepeatedBatches( candyFlavors = List.of( "cherry", "mint", "mint", "mint", "mint", "lemon", "berry" ) )
Output: List.of("1,4")
The four mint candies from indices 1 through 4 form a repeated batch.
findRepeatedBatches( candyFlavors = List.of( "apple", "apple", "mint", "mint", "berry" ) )
Output: List.of()
No flavor appears at least three times consecutively.
findRepeatedBatches( candyFlavors = List.of( "orange", "orange", "orange", "lime", "berry", "berry", "berry", "vanilla", "vanilla", "vanilla", "vanilla", "mint" ) )
Output: List.of("0,2", "4,6", "7,10")
The orange, berry, and vanilla candies form three separate repeated batches.
findRepeatedBatches( candyFlavors = List.of( "mango", "mango", "mango", "mango", "mango" ) )
Output: List.of("0,4")
All five candies form one complete repeated batch.