Unit 4 Session 1 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What is the structure of the input?
Q: What is the output?
Q: What should the function return if all memes are longer than the maximum length?
Q: Are there any constraints on the input, such as the presence of non-alphanumeric characters?
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Iterate through the list of memes and check each meme's length. If the length is within the acceptable limit, add it to the list of filtered memes.
1) Initialize an empty list called `filtered_memes`.
2) For each `meme` in `memes`:
a) If the length of `meme` is less than or equal to `max_length`, append it to `filtered_memes`.
3) Return the `filtered_memes` list.
**⚠️ Common Mistakes**
- Forgetting to handle cases where the input list is empty.
- Incorrectly calculating the length of the memes, leading to filtering errors.
def filter_meme_lengths(memes, max_length):
filtered_memes = []
for meme in memes:
if len(meme) <= max_length:
filtered_memes.append(meme)
return filtered_memes