Perl Weekly Challenge 221: Good Strings
These are some answers to the Week 221, task 1, of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on June 18, 2023 at 23:59). This blog post offers some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Good Strings
You are given a list of @words
and a string $chars
.
A string is good if it can be formed by characters from $chars, each character can be used only once.
Write a script to return the sum of lengths of all good strings in words.
Example 1
Input: @words = ("cat", "bt", "hat", "tree")
$chars = "atach"
Output: 6`
The good strings that can be formed are "cat" and "hat" so the answer is 3 + 3 = 6.