Sort Array By Parity II

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.
Given an array of integers nums, half of the integers in nums are odd, and the other half are even.
Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.
Return any answer array that satisfies this condition.
LeetCode Problem - 922
class Solution {
public int[] sortArrayByParityII(int[] nums) {
// Initialize a new array to store the sorted numbers.
int[] newArr = new int[nums.length];
// Counters to keep track of the positions for even and odd numbers.
int countEven = 0;
int countOdd = 1;
// Loop through the original array.
for(int i=0; i<nums.length; i++){
// If the number is even.
if(nums[i]%2 == 0){
newArr[countEven] = nums[i]; // Place even number at even index.
countEven +=2; // Move to the next even index.
}
// If the number is odd.
else{
newArr[countOdd] = nums[i]; // Place odd number at odd index.
countOdd += 2; // Move to the next odd index.
}
}
// Return the sorted array.
return newArr;
}
}




