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

 

max


Given a non-empty array of integers, recursively compute the largest value in the array. Note: You should solve this recursively (no loops). You will need a recursive helper method that takes an array and an index as parameters. Advice: If there are at least two items to look at, then do the following: look at the first number, and let recursion tell you the max of the rest of the numbers. Return whichever is bigger. Challenge: If you use Math.max() as part of your solution, you can solve this in 2 lines of code.


max([3, 5, 1]) → 5
max([-2, 0, 4, 12]) → 12
max([8, 8, 8, 8, 8]) → 8

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

int max(int[] nums) { }

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