Skip to content
Discussion options

You must be logged in to vote

We need to determine if the given array is "special" by checking if every pair of adjacent elements contains two numbers with different parity (one even and one odd). Here's how you can implement this:

  1. Check the length of the array: If the array has only one element, it is automatically considered special.
  2. Iterate through the array: For each pair of adjacent elements, check if they have different parity.
  3. Return the result: If all adjacent pairs have different parity, return true; otherwise, return false.

Let's implement this solution in PHP: 3151. Special Array I

<?php
/**
 * @param Integer[] $nums
 * @return Boolean
 */
function isArraySpecial($nums) {
    $length = count($nums);

    /…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Feb 1, 2025
Maintainer Author

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Feb 1, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Feb 1, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants