Given an array with N elements and an array of N indices find the lowest possible amounts of swaps So I have two arrays $d$ and $s$ with size $n \in \mathbb{N}$. Array $d$ contains the elements and array $s$ contains indices. Array $s$ contains all numbers from $0$ upto $n$ with no duplicates.

The indices in $s$ indicate where the elements in $d$ need to go. So the element at $d[q]$
needs to be at $d[s[q]]$ where $n &gt; q \geq 0$. 

The goal is to find the minimum amount of $q \in \mathbb{N}$ swaps such that the after all swaps are performed the above holds.
Hint: Assume you have four items that are in order a,b,c,d but you want them in order b, c, d, a. How many swaps do you need and why? 

Then you generalise this to the whole array.