FastPrepReplace Values and Return Sums
Problems/Replace Values and Return Sums

Replace Values and Return Sums

Amazon logoAmazonFULLTIMEOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an integer array entries and a 2D integer array transactions. Each transaction is a pair [oldValue, newValue].

For each transaction, replace every occurrence of oldValue in entries with newValue. After applying the transaction, record the sum of all values in entries.

Return an array containing the recorded sums after each transaction.

The sums may exceed the range of a 32-bit integer.

Function

replaceValuesAndReturnSums(entries: int[], transactions: int[][]) → long[]

Examples

Example 1

entries = [1, 2, 1, 3]transactions = [[1, 4], [2, 1], [4, 2]]return = [13, 12, 8]

After replacing 1 with 4, the array is [4,2,4,3] with sum 13. After replacing 2 with 1, the sum is 12. After replacing 4 with 2, the sum is 8.

Example 2

entries = [5, 5]transactions = [[1, 2], [5, 1]]return = [10, 2]

The first transaction has no matching value, so the sum stays 10. The second transaction changes both values to 1, so the sum becomes 2.

Constraints

  • transactions[i].length == 2
  • The returned sums may require 64-bit integers.

More Amazon Online Assessment questions

  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public long[] replaceValuesAndReturnSums(int[] entries, int[][] transactions) {
      // write your code here
    }
}
Checking account…