Trains the technique from
LeetCode 2574Left and Right Sum DifferencesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A grain terminal lines up its silos in one row. Silo i currently holds nums[i] tonnes.
For each silo the operator wants its imbalance: the absolute difference between the tonnage stored in the silos strictly before it in the row and the tonnage stored in the silos strictly after it. The silo itself counts on neither side, and an empty side contributes zero.
Return an array of the imbalances, one entry per silo, in row order.
Example 1
For silo 0 nothing lies before it and 2 + 9 + 4 = 15 lies after it. For silo 1 the sides hold 6 and 13. For silo 2 they hold 8 and 4. For silo 3 they hold 17 and nothing.
Example 2
Silo 0 has nothing before it and 5 tonnes after it. Silo 1 has 12 tonnes before it and nothing after it.
Example 3
The middle silo has 3 tonnes on each side, so its imbalance is 0, while each end silo faces 6 tonnes on its inner side and nothing on its outer side.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def left_right_difference(nums: list[int]) -> list[int]:public int[] leftRightDifference(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.