Special Array I

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
An array is considered special if every pair of its adjacent elements contains two numbers with different parity.
You are given an array of integers nums. Return true if nums is a special array, otherwise, return false.
LeetCode Problem - 3151
class Solution {
// Method to determine if an array is "special"
// An array is "special" if consecutive elements have different parities (one is even, the other is odd)
public boolean isArraySpecial(int[] nums) {
// If the array has only one element, it's considered special
if(nums.length == 1) return true;
// Iterate over the array elements except the last one
for(int i = 0; i < nums.length - 1; i++) {
// Check the parity of consecutive elements
boolean flag = checkParity(nums[i], nums[i + 1]);
// If consecutive elements have the same parity, return false
if(!flag) return false;
}
// If all consecutive elements have different parities, return true
return true;
}
// Method to check the parity of two numbers
public boolean checkParity(int x, int y) {
// Determine the parity of the first number
boolean temp1;
if(x % 2 == 0) temp1 = true; // Even
else temp1 = false; // Odd
// Determine the parity of the second number
boolean temp2;
if(y % 2 == 0) temp2 = true; // Even
else temp2 = false; // Odd
// Return true if the numbers have different parities, otherwise return false
if(temp1 == temp2) return false;
else return true;
}
}




