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

 

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

Given an array of int values called nums, determine and return a boolean representing whether each adjacent pair of elements has the opposite even-oddness. Thus, if the element at index X is odd, the element at index X+1 must be even. That also means the element at index X-1 must be even. If the element at index X is even, the elements at indexes X-1 and X+1 must be odd. The above condition also applies to the pair comprised of the last and first elements of the array (the logic wraps around). We'll say that an empty array passes this test, because there are no pairs that could have the same even-oddness to serve as a reason to reject the input.


HINTS: are there opportunities for early return in this problem?  Are there circumstances where the alternation pattern described above is impossible?  Are you dealing with negative element values appropriately?  Could you update a loop control variable by different values and still get accurate results?

apcsaArraysIsEvenOdd([0, 1, 2, 3]) → true
apcsaArraysIsEvenOdd([1, 0, 3, 2]) → true
apcsaArraysIsEvenOdd([0, 2, 1, 3]) → false

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

public boolean apcsaArraysIsEvenOdd(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: 240

Copyright Nick Parlante 2017 - privacy