#C5026. Concatenated String Formation Check
Concatenated String Formation Check
Concatenated String Formation Check
You are given a target string s
and a list of words. Your task is to determine whether the string s
can be formed by concatenating all the words in the list in any order. This is equivalent to checking whether the frequency of each character in s
exactly matches the combined frequency of the characters in the given words.
In mathematical terms, let \(f(c, x)\) denote the frequency of character \(c\) in string \(x\). You need to verify if for every character \(c\),
\[
f(c, s) = \sum_{w \in \text{words}} f(c, w)
\]
If the condition holds for all characters, output True
; otherwise, output False
.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains the string
s
. - The second line contains an integer
n
representing the number of words. - The next
n
lines each contain a single word.
outputFormat
Output a single line to standard output (stdout) containing either True
or False
depending on whether the target string can be formed by concatenating the words in any order.
leetcode
2
leet
code
True