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

 

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

Given an array of String values, find and return the number of pairs of equal consecutive elements.


HINTS: This is a "compare neighbors" algorithm, so you need to compare the element at index i with the element at index i+1 (or i-1, your choice).  Be careful of off-by-one errors, which are a common issue with this type of algorithm.  Also: how should you compare String values?

apcsaArraysCountConsecutiveEquals(["hi", "hi", "ho", "ho", "ho", "ho", "hi"]) → 4
apcsaArraysCountConsecutiveEquals(["a", "b", "c"]) → 0
apcsaArraysCountConsecutiveEquals([]) → 0

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

public int apcsaArraysCountConsecutiveEquals(String[] arr) { }

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

Copyright Nick Parlante 2017 - privacy