As reported: DoorDash coding question (2025), filed with a depth-first search tag.
You are given an array nums and a string s made of the characters 'F', 'W' and '?'. Every '?' must be replaced by 'F' or 'W'. A filling is valid when the runs of consecutive Fs in the result have exactly the lengths in nums, in order: the first run has nums[0] Fs, the second nums[1], and so on, with no other Fs. Runs are separated by at least one W.
Return the number of valid fillings.
Example 1
nums = [1,2]
s = "?W??FW"
Output: 1
Only "FWWFFW" works; for example "WWFFFW" has a single run of three.
Example 2
nums = [1,1]
s = "?WW??"
Output: 2
"FWWFW" and "FWWWF".
Example 3
nums = [1,1]
s = "WW??W"
Output: 0
Two runs of one F each need at least three characters (F, W, F), and only two are free.
Constraints: 1 ≤ s.length ≤ 50; 1 ≤ nums.length ≤ 25; 1 ≤ nums[i] ≤ 50. The answer fits in a 64-bit signed integer.
Code runner format: one JSON value per line: nums, then s. Implement countValidPatterns(nums, s); the harness prints the count.