Description

Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ransomNote.

Examples

Input:ransomNote = "a", magazine = "b"
Output:false
Explanation:

The ransom note requires 'a', but the magazine only contains 'b'. Without the required letter available, the note cannot be constructed.

Input:ransomNote = "aa", magazine = "ab"
Output:false
Explanation:

The ransom note needs two 'a' letters, but the magazine 'ab' only provides one 'a'. Each letter can only be used once, so construction fails.

Input:ransomNote = "aa", magazine = "aab"
Output:true
Explanation:

The ransom note needs two 'a' letters. The magazine 'aab' contains two 'a' letters and one 'b', which is sufficient to construct the note.

Constraints

  • 1 ≤ ransomNote.length, magazine.length ≤ 10⁵
  • ransomNote and magazine consist of lowercase English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!