[Facebook面经】Phone | Number of Binary Arrays Facebook OA 数据岗

胖蛋 2020-7-17 726


The question asks the number of possible binary arrays (lets call it nums) of length n that meets the following conditions:

  1. nums.size() = n;
  2. nums[0] = nums[n-1] = 0;
  3. nums[i] (0 <= i < n) can only be 0 or 1
  4. length of consecutive 0s or 1s cannot exceed 3 (i.e. you cannot have ...0000... or ...1111....in the array)

For example:

n = 3, we have 000, 010, a total of 2 possible arrays

n = 4, we have 0010, 0100, 0110, a total of 3 possible arrays

最新回复 (0)
返回