Back to Pinterest questions
CodingSoftware Engineer

Ransom Note from wiki.txt

Frequency: Reported


Imagine you need to construct a ransom note by cutting individual characters from a page. Determine whether the source page contains enough copies of every required character.

The input file wiki.txt contains:

text
Pinterest is an image sharing and social media service designed to enable saving
and discovery of information (specifically "ideas")[8] on the internet using
images, and on a smaller scale, animated GIFs and videos,[9] in the form of
pinboards.[10] The site was created by Ben Silbermann, Paul Sciarra, and Evan
Sharp, and had over 430 million global monthly active users as of February
2022.[4] It is operated by Pinterest, Inc., based in San Francisco.

Write a program that reads wiki.txt, accepts a ransom note, and returns True exactly when the note can be constructed from the file.

Rules:

  • Matching is case-insensitive.
  • Only alphanumeric characters are considered.
  • Ignore punctuation and whitespace.
  • Each source character may be used at most once.

Examples

text
Input:  Get 30k. Do NOT notify the FBI or police. Bills in 20s.
Output: False
Reason: The source contains no k.
text
Input:  Put money into a white box and leave behind the car on the west.
Output: False
Reason: The note needs two w characters, but the source has one.
text
Input:  Do as I say if you ever want to see Princess Peach again!
Output: True

A fourth visible example begins PAY PAY PAY PAY PAY PAY PAY, but its output and explanation are cut off in the source screenshot.