import collections


def ransom_note_from_magazines(text, note):
    """Return True if `note` can be constructed with the letters
    present in text.

    TC: O(N + M), where N = len(note) and M = len(text)
    SC: O(U), where U = len(set(note)) (unique letters on `note`)
    """
    if len(note) > len(text):
        return False

    letters_needed = collections.defaultdict(int)

    # TC: O(N), where N = len(note)
    # SC: O(U), where U = len(set(note))
    for c in note:
        letters_needed[c] += 1

    # TC: O(M), where M = len(text)
    for c in text:
        if c in letters_needed:
            letters_needed[c] -= 1
            if letters_needed[c] == 0:
                letters_needed.pop(c)
        if not letters_needed.keys():
            return True

    return False