Construct Target String From a Character Bag
Problem statement
Given lowercase English strings bag and target, return whether target can be constructed using the character occurrences in bag.
Each occurrence in bag may be used at most once. Character order does not matter.
Function
canConstructTarget(bag: String, target: String) → booleanExamples
Example 1
bag = "aabbc"target = "abc"return = trueThe bag supplies at least one a, b, and c.
Example 2
bag = "abc"target = "aabc"return = falseThe target needs two occurrences of a, but the bag has only one.
Example 3
bag = "zzxy"target = "xyz"return = trueOrder is irrelevant; x, y, and one z are available.
Constraints
0 <= bag.length, target.length <= 1000000.- Both strings contain only lowercase English letters.