Find Minimum Operations to Make All Elements Divisible by Three

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.
You are given an integer array nums. In one operation, you can add or subtract 1 from any element of nums.
Return the minimum number of operations to make all elements of nums divisible by 3.
LeetCode Problem - 3190
class Solution {
public int minimumOperations(int[] nums) {
// Initialize result to store the total minimum operations
int result = 0;
// Iterate through each number in the array
for(int i = 0; i < nums.length; i++) {
// Calculate the remainder when the number is divided by 3
int remainder = nums[i] % 3;
// Calculate the minimum operations to make the number divisible by 3
// This can be either reducing by the remainder or increasing by (3 - remainder)
result += Math.min(remainder, 3 - remainder);
}
// Return the total minimum operations required
return result;
}
}




