Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
528 B
5
Indexable
Never
def countViral(video, engagementArray, k):
    count = 0
    subset = []

    def dfs(i):
        nonlocal count
        if i >= len(video):
            if subset:
                substring = "".join(subset)
                weak_count = sum(engagementArray[ord(ch) - ord('a')] for ch in substring)
                if 0 < weak_count <= k:
                    count += 1
            return

        subset.append(video[i])
        dfs(i + 1)
        subset.pop()
        dfs(i + 1)

    dfs(0)
    return count
Leave a Comment