FastPrepFastPrep
Problem Brief

Enumerating Narrative Sections πŸ‘©β€πŸŒΎ

FULLTIMEOA
See Meta online assessment and hiring insights

Imagine you have an bucket of numbers, each representing a character in a story. Now, imagine each character can be duplicated, like twins in a tale. Your task is to count how many sequences of characters in the story contain at least a certain number of pairs of twins.

In other words, you're looking for segments of the story where you can find enough pairs of characters that appear twice within that segment. These pairs must be distinct from each other and should occur at different points in the story.

1Example 1

Input
bucket = [0, 1, 0, 1, 0], n = 2
Output
3
Explanation
bucket[0 -> 3] = [0, 1, 0, 1] with bucket[0] = 0 = bucket[2] && bucket[1] = 1 = bucket[3] bucket[1 -> 4] = [1, 0, 1, 0] with bucket[1] = 1 = bucket[3] && bucket[2] = 0 = bucket[4] bucket[0 -> 4] = [0, 1, 0, 1, 0] with bucket[0] = 0 bucket[2] There are 3 sub-buckets that stisfy the criteria of containing at least n = 2 pairs of duplicate values: In each of these sub-buckets, there is at least one pair of 0s and one pair of 1s. P.S. For original prompt, pls refer to source img πŸ‘‡

Constraints

Limits and guarantees your solution can rely on.

Uknown for now
public int enumeratingNarrativeSections(int[] bucket, int n) {
    // write your code here
}
Input

bucket

[0, 1, 0, 1, 0]

n

2

Output

3

Sign in to submit your solution.