id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-encryption > apcsaFindStretchedAnagrams
prev  |  next  |  chance

Given an input String with a mixture of letters and other characters and an ArrayList of words to look for, plus a threshold number, find and return a message containing "stretched" anagrams in the input from the word list separated by spaces. A stretched anagram is a sequence of letters that contains all the letters in another word, but may have a few extra letters as well. So for example while "card" cannot be found in "cart", it is possible to find "card" within "Cart a dumbell around" if the threshold value is 2 (expand the search for "card" to include up to 2 extra letters). Note that the words ArrayList is going to contain a bunch of extra words that cannot be found in the input, even stretched: your task is to find and sequence only the words that are found.


Seeing the problems before this one, perhaps you have been wondering what a bunch of anagram problems are doing in a set about encryption.  Now you have an answer: you are coding a technique for steganography, hiding secret information within seemingly-innocent other information.  Most students are introduced to steganography through digital photo manipulation, but text is also everywhere, and techniques for textual steganography have been employed for a very long time.

Preconditions: words contains Strings of only lowercase letters.  The threshold value will be greater than or equal to 0.  (A threshold of 0 means that the anagrams will be found with no extra letters, as in the earlier apcsaIndexOfAnagram problem.)

HINT: because of the stretching threshold, you are likely to "find" the same word multiple times starting at consecutive locations.  How do you deal with that possibility?

HELPFUL TIP: when making output that joins together an ArrayList into a String, use String.join(String separator, List words) such as String.join(" ", words)

apcsaFindStretchedAnagrams("Cart a dumbell around", ["squish", "tumuli", "card", "chomp", "snottiest", "unspeak"], 2) → "card"
apcsaFindStretchedAnagrams("Have you seen the new Playskool toys? Nice score lifting those from the shelf!", ["birched", "infests", "look", "beths", "closer", "odes", "paraquats"], 0) → "look closer"
apcsaFindStretchedAnagrams("Don't touch that, it's grandma's catheter!", ["declaims", "stretcher", "jatos", "unmeetly", "malignancy", "anagram", "choiceness"], 6) → "anagram stretcher"

...Save, Compile, Run (ctrl-enter)

public String apcsaFindStretchedAnagrams(String input, ArrayList<String> words, int threshold) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 350

Copyright Nick Parlante 2017 - privacy