Left and Right Sum Differences

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 a 0-indexed integer array nums, find a 0-indexed integer array answer where:
answer.length == nums.length.answer[i] = |leftSum[i] - rightSum[i]|.
Where:
leftSum[i]is the sum of elements to the left of the indexiin the arraynums. If there is no such element,leftSum[i] = 0.rightSum[i]is the sum of elements to the right of the indexiin the arraynums. If there is no such element,rightSum[i] = 0.
Return the array answer.
LeetCode Problem - 2574
class Solution {
public int[] leftRightDifference(int[] nums) {
// Initialize an array to store the result
int[] resultArr = new int[nums.length];
// Initialize arrays to store the left and right sums
int[] rightSumArray = new int[nums.length];
int[] leftSumArray = new int[nums.length];
// Calculate left sums
int temp = 0;
for(int i=0; i<nums.length; i++){
if(i != 0){
temp += nums[i-1];
leftSumArray[i] = temp;
}
else{
leftSumArray[i] = temp;
}
}
// Calculate right sums
for(int i=0; i<nums.length; i++){
temp = 0;
for(int j=i+1; j<nums.length; j++){
temp += nums[j];
}
rightSumArray[i] = temp;
}
// Calculate absolute differences between left and right sums and store them in resultArr
for(int i=0; i<nums.length; i++){
resultArr[i] = Math.abs(leftSumArray[i] - rightSumArray[i]);
}
return resultArr;
}
}




