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

 

gaurav.gupta@mq.edu.au arrays > maxProfit
prev  |  next  |  chance

Define a function that, assuming the parameters:
- The daily prices of a particular stock (in chronological order) in an array, and,
- An int representing the number of days;
Returns the highest profit for that EXACT time range. For example, if prices = {13, 16, 20, 20, 21, 23, 28, 22, 24, 24, 24, 25, 35, 28, 30} and days = 5, return 11 (stock jumping from 24 to 35).


maxProfit([13, 16, 20, 20, 21, 23, 28, 22, 24, 24, 24, 25, 35, 28, 30], 5) → 11
maxProfit([13, 16, 20, 20, 21, 23, 28, 22, 24, 24, 24, 25, 35, 28, 30], 2) → 10
maxProfit([13, 16, 20, 20, 21, 23, 28, 22, 24, 24, 24, 25, 35, 28, 30], 1) → 0

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

int maxProfit(int[] prices, int nDays) { }

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: 4 Post-solution available

Copyright Nick Parlante 2017 - privacy