[英]Interview Coding Problem (OA): Counting Number of Alternating Sequences of size k in array of 1s and 0s
給定一個由 1 和 0 組成的數組和一個 integer k 找到數組中大小為 k 的交替序列的數量。 將數組視為循環,這意味着數組的最后一個索引跟隨第一個索引。 例子:
array = [1,0,1,0,1,1], k = 4
solution_set = {1010, 0101}
result = 2
array = [1,0,1,0], k = 3
solution_set = {101, 010, 101(starting at 3rd index), 010(starting at 4th index}
result = 4
我沒有足夠快地得到答案,並且有一個不必要的復雜算法有沒有人有這樣做的好方法。 甚至不確定 dp 是否是最好的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.