Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mr Y and his Transport Problem #104

Open
keivalya opened this issue Sep 29, 2020 · 2 comments
Open

Mr Y and his Transport Problem #104

keivalya opened this issue Sep 29, 2020 · 2 comments

Comments

@keivalya
Copy link
Contributor

Mr X has a huge transport business, where his company provides trucks to transfer goods. Mr Y has a manufacturing facility where it has N number of loading areas. Mr Y orders N trucks from Mr X for transportation of each of its manufactured products. One day the trucks were misaligned corresponding to their loading areas. Mr Y wants to swap trucks one by one to place them at their true positions in such a way that there is a minimum number of swaps between trucks. Note that all trucks are already at the misplaced loading area, swap occurs between two trucks at a time and truck is numbered based on its loading area number that is both loading area and truck have the same number and loading area are denoted by 1 to N.

Input:
1 <= N <= 50
1st Line: integer N which denotes the number of loading areas
2nd Line: N space-separated integers denoting truck numbers parked on 1 to N loading area.

Output:
Number denoting a minimum number of swaps.

Sample input
10
1 3 2 4 9 6 7 5 8 10

Sample output
3

@JINDAL-JJ
Copy link

I can do this code in Python. Please mention the folder to add this code and assign me over this issue. Thank You!

@BassCoder2808
Copy link

I have solved the above problem in Python. It's time complexity is O(n log(n)).
Here is the SS for the above solved example.
PS C:\Users\vedant jolly\Desktop> python .\hacktober.py
10
1 3 2 4 9 6 7 5 8 10
3
Please mention the folder in which I have to add the file. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants