Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Solution: Left and Right Sum Differences (easy)

Problem Statement

Given an input array of integers nums, find an integer array, let's call it differenceArray, of the same length as an input integer array.

Each element of differenceArray, i.e., differenceArray[i], should be calculated as follows: take the sum of all elements to the left of index i in array nums (let's call it leftSum<sup>i</sup>), and subtract it from the sum of all elements to the right of index i in array nums (let's call it rightSum<sup>i</sup>), taking the absolute value of the result:

<center>

.....

.....

.....

Like the course? Get enrolled and start learning!