Valid FW Patterns
Anonymous User
620

Description:
You are given an array nums where each element represents the required count of consecutive F characters. You are also given a string s containing characters F, W, and ?. Each ? can be replaced by either F or W. The task is to determine how many valid FW patterns can be formed, where the conditions are:

Each number in nums corresponds to exactly that many consecutive F characters in the string.
Consecutive F groups must be separated by at least one W.
Every ? in the string must be replaced with either F or W.
Example 1:
Input:
nums = [1, 2]
s = "?W??FW"
Output:
1
Explanation:
The only valid pattern is FWWFFW. Other patterns, such as WWFFFW, do not satisfy the condition of exactly 1 and 2 consecutive Fs.

Example 2:
Input:
nums = [1, 1]
s = "?WW??"
Output:
2
Explanation:
The valid patterns are FWWFW and FWWWF.

Example 3:
Input:
nums = [1, 1]
s = "WW??W"
Output:
0
Explanation:
No valid pattern can be formed because the required two separate groups of 1 F cannot be satisfied.

Comments (6)