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

 

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

Given an ArrayList of Integers and an int target, find and return the index whose value is closest to the target. In the case of a tie, return the first index of the tied values. Precondition: lst will have at least one element.


apcsaListFindClosest([1, 3, 4, 5, 6], 8) → 4
apcsaListFindClosest([1], 3) → 0
apcsaListFindClosest([0, 1, 2, 3, 4], 4) → 4

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

public int apcsaListFindClosest(ArrayList<Integer> lst, int target) { }

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

Copyright Nick Parlante 2017 - privacy