You’re on-call for a fintech platform processing millions of card payments per day. Every payment provider webhook includes a compact “signature pattern” that your edge service must validate before accepting the event (rejecting invalid signatures prevents fraud and reduces chargeback risk).
A signature pattern is a string containing only:
'(' and ')' — literal parentheses'*' — a wildcard that can represent either '(', ')', or the empty string ''A signature is considered valid if there exists some replacement of every '*' such that the resulting string is a balanced parentheses string.
Implement is_valid_signature(pattern: str) -> bool.
A balanced parentheses string means:
#('(') >= #(')').Example 1
pattern = "(*)"True'*' with '' to get "()", which is balanced.Example 2
pattern = "(*))"True'*' with '(' to get "(())".Example 3
pattern = ")*("False')'. No replacement of '*' can fix the invalid prefix.1 <= len(pattern) <= 10^5pattern[i] is one of '(', ')', '*'