Tap here to switch tabs
Problem
Submissions

Problem: Relocate Marbles

med
30 min
Try to solve the Relocate Marbles problem.

Statement

You are given a 00 indexed integer array nums representing the initial positions of several marbles. You are also given two 00 indexed integer arrays moveFrom and moveTo of equal length.

Across moveFrom.length steps, you relocate the marbles. On the iextthi^{ ext{th}} step, you move all marbles situated at position moveFrom[i] to position moveTo[i].

Return the sorted list of unique positions that contain at least one marble after completing all moves.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq moveFrom.length ≤105\leq 10^5

  • moveFrom.length ==== moveTo.length

  • 1≤1 \leq nums[i], moveFrom[i], moveTo[i] ≤109\leq 10^9

  • The test cases are generated such that there is at least one marble at moveFrom[i] when applying the iextthi^{ ext{th}} move.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Relocate Marbles

med
30 min
Try to solve the Relocate Marbles problem.

Statement

You are given a 00 indexed integer array nums representing the initial positions of several marbles. You are also given two 00 indexed integer arrays moveFrom and moveTo of equal length.

Across moveFrom.length steps, you relocate the marbles. On the iextthi^{ ext{th}} step, you move all marbles situated at position moveFrom[i] to position moveTo[i].

Return the sorted list of unique positions that contain at least one marble after completing all moves.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq moveFrom.length ≤105\leq 10^5

  • moveFrom.length ==== moveTo.length

  • 1≤1 \leq nums[i], moveFrom[i], moveTo[i] ≤109\leq 10^9

  • The test cases are generated such that there is at least one marble at moveFrom[i] when applying the iextthi^{ ext{th}} move.