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

 

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

Given an ArrayList of Integers, find out if any element of the list has a value with more digits than the element before it. If so, take off the extra rightmost digits and add them as their own integer element at the end of the ArrayList. Keep processing the list from beginning to end until you cannot make any more such changes - in many cases, your algorithm will require more than one pass! By the time your processing is done, all items in the ArrayList will have nonincreasing numbers of digits. Return the modified ArrayList.


EXAMPLE

Suppose the input had three elements, with these values.
[105, 912534490, 32]
After one pass, the ArrayList looks like this:
[105, 912, 32, 534490]
After two passes:
[105, 912, 32, 53, 4490]
After a third and final pass, the output is:
[105, 912, 32, 53, 44, 90]
Note that -5 still only has one digit (it also has a negative sign). Also, you might need to process more items than you originally thought.

HINT

There are a few different ways to figure out how many base-10 digits a number has.  For a more interesting challenge, don't use String.

apcsaListMoveExtraDigits([105, 912534490, 32]) → [105, 912, 32, 53, 44, 90]
apcsaListMoveExtraDigits([9, 19]) → [9, 1, 9]
apcsaListMoveExtraDigits([-5, 3, 2]) → [-5, 3, 2]

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

public ArrayList<Integer> apcsaListMoveExtraDigits(ArrayList<Integer> 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