Google | Phone Screen | Min swaps to sort array
Anonymous User
41484

Given an array return an integer indicating the minimum number of swap operations required to sort the array into ascending order.

Example 1:

Input: [5, 1, 3, 2]
Output: 2
Explanation: [5, 1, 3, 2] -> [2, 1, 3, 5] -> [1, 2, 3, 5]

Example 2:

Input: [1, 3, 2]
Output: 1
Explanation: [1, 3, 2] -> [1, 2, 3]
Comments (44)