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

 

orion.a.smith@gmail.com apcsa-arrays > apcsaArraysCountIncrements
prev  |  next  |  chance

Given an array of ints, return the number of times that one element is directly followed by another element with a value of one greater. Thus, if the element at index 3 has the value 40 and the element at index 4 has the value 41, that counts once toward the number you are building.

HINT
You will need to compare two side-by-side elements using your loop control variable and either the variable plus one or minus one. Be careful about the edge cases at the beginning and end!

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

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

public int apcsaArraysCountIncrements(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: 220

Copyright Nick Parlante 2017 - privacy