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

 

norm.krumpe@muohio.edu > indexOf
prev  |  next  |  chance

Given an array and a key, return the index of the first occurrence of the key in the array, or return -1 if the key is not found in the array. This is the standard linear search algorithm, but solved recursively. Note: You should solve this recursively (no loops). You will need a recursive helper method that takes an array and a key and an index as parameters.


indexOf([3, 7, 5], 3) → 0
indexOf([3, 8, 2, 2], 2) → 2
indexOf([4, 8, 15, 16, 23, 42], 99) → -1

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

int indexOf(int[] nums, int key) { }

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

Copyright Nick Parlante 2017 - privacy