You are given two strings, note and magazine. Return true if note can be constructed by using the letters from magazine, where each letter in magazine can be used at most once. Otherwise, return false.
An empty note can always be constructed. A non-empty note cannot be constructed from an empty magazine.
Example 1:
Input: note = 'aa', magazine = 'aab'
Output: true
Explanation: The magazine contains two a characters and one b, which is enough to build aa.
Example 2:
Input: note = 'aa', magazine = 'ab'
Output: false
Explanation: The magazine has only one a, so aa cannot be constructed.
Example 3:
Input: note = '', magazine = 'abc'
Output: true
Explanation: An empty note requires no letters, so it is always constructible.
Example 4:
Input: note = 'a', magazine = ''
Output: false
Explanation: An empty magazine has no letters to build a non-empty note.
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay August 2026
Contest runs August 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.