Loading...
You are given an integer n and an integer array sources. Positions 0 to n - 1 sit in a row.
On day 0 every position listed in sources is marked. On each later day, every position that is already marked also marks the positions next to it, which are i - 1 and i + 1 when they exist. A position stays marked once it is marked, and every position is marked eventually.
A record lists all n positions, each exactly once. A record is valid when a position marked on an earlier day always comes before a position marked on a later day. Positions marked on the same day may appear in any order relative to each other. The positions in sources are all marked on day 0, so they form one such group as well.
Return the number of distinct valid records. Mod the result by 10 ** 9 + 7.
Input: n = 5, sources = [2]
Output: 4
Explanation: Position 2 is marked on day 0, positions 1 and 3 on day 1, and positions 0 and 4 on day 2. The two day-1 positions can be listed in 2 orders and the two day-2 positions in 2 orders, so there are 4 records.
Input: n = 6, sources = [2,4]
Output: 12
Explanation: Positions 2 and 4 are marked on day 0, positions 1, 3 and 5 on day 1, and position 0 on day 2. The day-0 group can be listed in 2 orders and the day-1 group in 6 orders, so there are 12 records.
Input: n = 1, sources = [0]
Output: 1
Explanation: The single position is marked on day 0, so the only record lists that position on its own.
sources.length ≤nsources[i] ≤n−1sources are distinct, and they are not necessarily sorted