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

 

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

Given an ArrayList of Integers and an int num, find the element that is greater than the smallest num elements of the list. Re-position that element only, so that it now appears at index num instead of its original index. Return the modified ArrayList.


Preconditions: 0 <= num < lst.size(), and the value of the desired element will not be repeated in lst.

HINT

You know how to find the minimum element of a collection.  Can you do that more than once?  How would you keep track of which elements were smaller than the desired element?

apcsaListMoveGreaterThan([2, 1], 1) → [1, 2]
apcsaListMoveGreaterThan([1, 2], 1) → [1, 2]
apcsaListMoveGreaterThan([5, 4, 3, 2, 1], 1) → [5, 2, 4, 3, 1]

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

public ArrayList<Integer> apcsaListMoveGreaterThan(ArrayList<Integer> lst, int num) { }

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