Official algorithmic problem description and constraints.
Given two arrays of distinct positive integers π and π of length π, we would like to make both the arrays the same. Two arrays π₯ and π¦ of length π are said to be the same when for all 1β€πβ€π, π₯π=π¦π.
Now in one move, you can choose some index π and π in π (πβ€π) and swap ππ and ππ, then choose some π and π (πβ€π) in π such that πβπ=πβπ and swap ππ and ππ.
Is it possible to make both arrays the same?
Detailed video explanations, mathematical intuition, and clean C++ implementation code.