about | help | code help+videos | done | prefs |
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.FYIThe data type of the output is List<String> just because CodingBat does not allow the creation of methods with a return type of ArrayList<String>. Because an ArrayList is-a List, you can safely pretend that the return type is ArrayList<String> instead of trying to create something called a List. The AP CSA curriculum used to require that students know what a List is (an interface), but no longer requires that knowledge. 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) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 320
Copyright Nick Parlante 2017 - privacy