π Background Information
An old TV trope is the βcut and pasteβ ransom note. A scoundrel would cut out letters from a magazine or newspaper and paste them together into a note which would be sent to some victim. The idea was that the note is untraceable since they are not using their own handwriting. For example:
π― Problem Statement
Write a function that can efficiently determine if you can create a note given one or more articles of text.
β Acceptance Criteria
Write a function that takes two arguments - a string which is the note that you want to write as well as an array of strings which represent all of the magazine articles that you have to cut and paste letters from. The function should return true
if the note can be constructed by using the letters from magazine articles and false
otherwise.
- Each letter from the magazine articles can only be used once in the note.
- You do NOT have to worry about whitespace.
- You do NOT have to worry about the case of the characters (it is fine to use an upper case or lower case character interchangeably).
- You DO need to worry about special characters and punctuation (e.g. periods, semicolons, question marks, etc.).
π Dev Notes
- You could technically brute force this solution with some nested for loops. However, the goal of this lab is to implement an efficient solution. Use the hashmap data structure to your advantage!
- You are allowed to use the built-in hashmap data structures in the language that you are working in.
π₯οΈ Example Output
Here are some sample inputs and outputs for a function bool canCreateNote(string note, string[] articles)
:
Note | Articles | Output |
---|---|---|
a | [βaβ] | true |
a | [βabβ] | true |
a | [βaβ, βbβ] | true |
abc | [βaβ, βbβ, βcβ] | true |
The bird is red! | [βI write a lot.β, βTo and fro.β, βHere be deadly dragons!β] | true |
a | [βbβ] | false |
a | [βbcβ] | false |
a | [βbβ, βcβ] | false |
abc | [βaβ, βbβ, βdβ] | false |
The bird is red | [βI write a lot.β, βTo and fro.β] | false |
The bird is red! | [βI write a lot.β, βTo and fro.β, βHere be deadly dragonsβ] | false |
π Thought Provoking Questions
- What steps did you take to prepare your data? For example, did you combine the articles in some way? Did you filter out certain characters or whitespace?
- How did you efficiently compare the articles to the note? In other words, how did you utilize the hashmap data structure?
- Estimate the time complexity of your solution. Explain your reasoning.
πΌ Add-Ons For the Portfolio
N/A
π Useful Links
π Works Cited
N/A