Maximum Count of Positive Integer and Negative Integer

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.
Q - Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.
- In other words, if the number of positive integers in
numsisposand the number of negative integers isneg, then return the maximum ofposandneg.
Note that 0 is neither positive nor negative.
LeetCode Problem: Link | Click Here
class Solution {
public int maximumCount(int[] nums) {
// Initialize the result variable to store the maximum count
int result = 0;
// Get the length of the input array
int len = nums.length;
// Initialize counters for positive and negative integers
int positiveInt = 0;
int negativeInt = 0;
// Loop through each number in the array
for (int num : nums) {
// Check if the number is greater than 0 (positive)
if (num > 0) {
// Increment the count of positive integers
positiveInt++;
} else if (num < 0) { // Check if the number is less than 0 (negative)
// Increment the count of negative integers
negativeInt++;
}
}
// Find the maximum count between positive and negative integers
result = Math.max(positiveInt, negativeInt);
// Return the maximum count of positive or negative integers
return result;
}
}




