Facebook | Phone | Number of Binary Arrays

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-07-15Added By Anonymous
Source: Link

Company: Meta (Facebook)
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown

Original Post Content:

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
Should be solvable with DP but only got 10 minutes left for this question, didn't come up with one.

Update:
This is a very similar question to LC - 552. Student Attendance Record II.

Comments