result to store the final sum of intervals for each element.\n3. Perform the first pass from left to right:\n a. For each element in the array, update the running sum and count in the hash maps.\n b. Calculate the sum of intervals from the start to the current index using the formula current_index * count - running_sum and add it to result.\n4. Reset the hash maps for the second pass.\n5. Perform the second pass from right to left:\n a. For each element in the array, update the running sum and count in the hash maps.\n b. Calculate the sum of intervals from the current index to the end using the formula (array_length - current_index - 1) * count - running_sum and add it to result.\n6. Return the result array containing the sum of intervals for each element.