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

 

frew@mclean.com aplist > removeShorterStrings
prev  |  next  |  chance

Write a method removeShorterStrings that takes an ArrayList of Strings as a parameter and that removes from each successive pair of values the shorter string in the pair. For example, suppose that an ArrayList called list contains the following values: {"four", "score", "and", "seven", "years", "ago"} In the first pair, "four" and "score", the shorter string is "four". In the second pair, "and" and "seven", the shorter string is "and". In the third pair, "years" and "ago", the shorter string is "ago". Therefore, the call: removeShorterStrings(list); should remove these shorter strings, leaving the list as follows: "score", "seven", "years". If there is a tie (both strings have the same length), your method should remove the first string in the pair. If there is an odd number of strings in the list, the final value should be kept in the list.


removeShorterStrings(["four", "score", "and", "seven", "years", "ago"]) → ["score", "seven", "years"]
removeShorterStrings(["four", "score", "and", "seven", "ago"]) → ["score", "seven", "ago"]
removeShorterStrings(["four", "five", "and", "seven", "years", "ago"]) → ["five", "seven", "years"]

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

public List removeShorterStrings(ArrayList<String> list) { }

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

Copyright Nick Parlante 2017 - privacy