Build a note from characters
Return whether the characters in source can construct note, consuming each source character at most once. Matching is case sensitive.
from collections import Counter
stock = Counter('aab')
stock['a'] -= 1
print(stock)Reason about the state
Count available characters, decrement for the note, and reject the first shortage. Expected time is linear in both strings. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return whether the characters in source can construct note, consuming each source character at most once. Matching is case sensitive.
The explanation opens here once every check passes.