Get Final Locations
Updated
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:
List<Integer> locations: the starting locations of the dataList<Integer> movedFrom: where each move takes data fromList<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, wherenis the length oflocations1 <= m <= 10^5, wheremis the length ofmovedFrom, andmovedTo.length == m1 <= locations[i], movedFrom[j], movedTo[j] <= 10^9- All values in
locationsare distinct. - Move
jstarts 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