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

 

jebbert@volusia.k12.fl.us > preEaglesIncOnly
prev  |  next  |  chance

Write a method that accepts an array of integers. Return an array of the same length but replace any decreasing numbers with the previous increasing number. For example: {15, 12, 17, 14, -4, 18, 19} In this array, 12 is a decreasing number, so it is replaced with 15. But then 17 is an increase compared to 15, so it is not replaced. 14 is not an increase over 17, so the 14 is replaced with 17. The -4 is also replaced with 17, but then 18 IS an increase compared to 17, so it is not replaced. Finally 19 is an increase over 18, so it is not replaced. The resulting array is: {15, 15, 17, 17, 17, 18, 19}. Look at the test data for additional examples.


preEaglesIncOnly([15, 12, 17, 14, -4, 18, 19]) → [15, 15, 17, 17, 17, 18, 19]
preEaglesIncOnly([]) → []
preEaglesIncOnly([7]) → [7]

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

public int[] preEaglesIncOnly(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: 250

Copyright Nick Parlante 2017 - privacy