Maximum Number of Operations With the Same Score 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.
Given an array of integers called nums, you can perform the following operation while nums contains at least 2 elements:
- Choose the first two elements of
numsand delete them.
The score of the operation is the sum of the deleted elements.
Your task is to find the maximum number of operations that can be performed, such that all operations have the same score.
Return the maximum number of operations possible that satisfy the condition mentioned above.
LeetCode Problem - 3038
class Solution {
public int maxOperations(int[] nums) {
// Initialize a counter to keep track of the number of operations
int count = 1;
// Calculate the sum of the first two elements of the array
int comp = nums[0] + nums[1];
// Loop through the array starting from the third element
for (int i = 2; i < nums.length - 1; i++) {
// Iterate over the remaining elements of the array
for (int j = i + 1; j < nums.length; j++) {
// Check if the sum of the current pair of elements equals the previously calculated sum
if ((nums[i] + nums[j] == comp)) {
// If it does, increment the count of operations and skip the next element
count++;
i++; // Skipping the next element
break; // Exit the inner loop
} else {
// If the sum does not match, return the current count of operations
return count;
}
}
}
// Return the final count of operations
return count;
}
}




