AlgoLounge

String Matching

easy

Check if string B can be formed using letters from string A, where each letter in A can be used at most once.

Examples

Example 1

Input:  A = "aab", B = "ab"
Output: true

Can use 1 'a' and 1 'b' from A to form B

Example 2

Input:  A = "ab", B = "aab"
Output: false

Need 2 'a's but A only has 1 'a'

Constraints

  • Both strings can be empty
  • Case-sensitive matching
TypeScript
Loading editor…
List of test cases (10)
Case 1
A = "aab"
B = "ab"
Case 2
A = "ab"
B = "aab"
Case 3
A = ""
B = ""
Case 4
A = "hello"
B = "ell"
Case 5
A = "world"
B = "door"
Case 6
A = "abc"
B = ""
Case 7
A = "programming"
B = "gram"
Case 8
A = "aaa"
B = "aaaa"
Case 9
A = "xyzabc"
B = "abc"
Case 10
A = "listen"
B = "silent"