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

 

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

Given a ciphertext str and a set of code words and phrases, remove entries from codes that are present in the ciphertext, but with a preference for longer entries. If one or more small entries in codes are found in str but a longer entry in codes is also found in str and includes the smaller entries, only remove the larger entry. Thus, entries in codes are only removed if they are not part of larger entries.


The code words/phrases could be present in any case (upper or lower or mixed), and could be present within other words in the ciphertext.  Return a toString of the codes ArrayList after the elements contained within str have been removed.  Although it will probably have less elements after the removals, the remaining elements must still be in their original order.

HINT: you may want to think about making a copy of codes, to have around while you start removing entries from the original.

apcsaExcludeHiddenWordsHard("I went fishing in the sea and found a large squid.", ["squid", "large squid", "in the sea", "tentacle", "fishing", "fish", "found", "the", "sea", "eats"]) → "[squid, tentacle, fish, the, sea, eats]"
apcsaExcludeHiddenWordsHard("how much wood could a woodchuck chuck if a woodchuck could chuck wood?", ["woodchuck", "chuck"]) → "[chuck]"
apcsaExcludeHiddenWordsHard("how much wood could a woodchuck chuck if a woodchuck could chuck wood?", ["wood", "woodchuck", "chuck", "could", "a wood", "chuck wood", "wood could"]) → "[wood, chuck, could]"

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

public String apcsaExcludeHiddenWordsHard(String str, ArrayList<String> codes) { }

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: 330

Copyright Nick Parlante 2017 - privacy