FastPrepGet Final Locations
Problems/Get Final Locations

Get Final Locations

Amazon logoAmazon● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Amazon stores its data on different servers at different locations. From time to time, due to several factors, Amazon needs to move its data from one location to another. This challenge involves keeping track of the locations of Amazon's data and reporting them at the end of the year.

At the start of the year, Amazon's data was located at n different locations. Over the course of the year, Amazon's data was moved from one server to another m times. Precisely, in the ith operation, the data was moved from movedFrom[i] to movedTo[i]. Find the locations of the data after all m moving operations. Return the locations in ascending order.

Note: the moves are performed in order, i = 0, 1, ..., m - 1. It is guaranteed that for any move:

  • There is data at movedFrom[i].
  • There is no data at movedTo[i].

Function

getFinalLocations(locations: List<Integer>, movedFrom: List<Integer>, movedTo: List<Integer>) → List<Integer>

Complete the function getFinalLocations in the editor.

getFinalLocations has the following parameters:

  1. List<Integer> locations: the starting locations of the data
  2. List<Integer> movedFrom: where each move takes data from
  3. List<Integer> movedTo: where each move puts it

Returns List<Integer>: the locations of the data after all moves, in ascending order

Examples

Example 1

locations = [1, 7, 6, 8]movedFrom = [1, 7, 2]movedTo = [2, 9, 5]return = [5, 6, 8, 9]

The data starts at locations 1, 6, 7 and 8. Move 0 goes from 1 to 2, so the data is at 2, 6, 7 and 8. Move 1 goes from 7 to 9: 2, 6, 8 and 9. Move 2 goes from 2 to 5: 5, 6, 8 and 9. In ascending order the answer is [5, 6, 8, 9].

Constraints

  • 1 <= n <= 10^5, where n is the length of locations
  • 1 <= m <= 10^5, where m is the length of movedFrom, and movedTo.length == m
  • 1 <= locations[i], movedFrom[j], movedTo[j] <= 10^9
  • All values in locations are distinct.
  • Move j starts at a location that holds data and ends at a location that holds no data at that moment.

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • Flat JSON Value DifferencesChubb · OAChubb interview questions
  • Items SortAkuna Capital · OAAkuna Capital interview questions
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
  • Array Rank TransformTata Consultancy Services · OATata Consultancy Services interview questions

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 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 Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public List<Integer> getFinalLocations(List<Integer> locations, List<Integer> movedFrom, List<Integer> movedTo) {
      // write your code here
    }

}
Checking account…