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

 

orion.a.smith@gmail.com apcsa-lists > apcsaListModMover
prev  |  next  |  chance

Given an ArrayList of Strings of varying lengths, move the even-length elements to the beginning of the list, but keep them in the order they were in relative to one another. By the end of this process, all the even-length Strings will be clustered at the beginning of the list and will be in the order they appeared in the original. All the odd-length Strings will appear after the even-length Strings, and will also be in their original relative order. Return the modified list.


Precondition: lst will have at least 1 element.

HINT

Keep from moving an element multiple times or you will be in an infinite loop!

apcsaListModMover(["a", "ab", "abc", "abcd"]) → ["ab", "abcd", "a", "abc"]
apcsaListModMover(["1", "3", "5"]) → ["1", "3", "5"]
apcsaListModMover(["junk", "junk", "har", "har", "junk"]) → ["junk", "junk", "junk", "har", "har"]

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

public List<String> apcsaListModMover(ArrayList<String> lst) { }

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

Copyright Nick Parlante 2017 - privacy