Skip to content

#2 Minimum_Swaps_2 passing solution#3

Open
Diamond-Dust wants to merge 1 commit intoYohanAvishke:masterfrom
Diamond-Dust:patch-1
Open

#2 Minimum_Swaps_2 passing solution#3
Diamond-Dust wants to merge 1 commit intoYohanAvishke:masterfrom
Diamond-Dust:patch-1

Conversation

@Diamond-Dust
Copy link
Copy Markdown

Original solution worked in O(n^2) time, while this one should work in O(n).
We organise the values into multiple cycles of swaps to be done. Number of needed swaps is a sum of the cycle sizes with each decreased by one (because it is a cycle after all).

Original solution worked in O(n^2) time, while this one should work in O(n). 
We organise the values into multiple cycles of swaps to be done. Number of needed swaps is a sum of the cycle sizes with each decreased by one (because it is a cycle after all).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant