Skip to content

raviseta/minimum-swaps-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

HackerRank solution for minimum-swaps-2

Problem

You are given an unordered array consisting of consecutive integers [1, 2, 3, ..., n] without any duplicates. You are allowed to swap any two elements. Find the minimum number of swaps required to sort the array in ascending order.

arr = [7, 1, 3, 2, 4, 5, 6]

Perform the following steps:

image

It took 5 swaps to sort the array.

Function Description

Complete the function minimumSwaps in the editor below.

minimumSwaps has the following parameter(s):

int arr[n]: an unordered array of integers

Returns

int: the minimum number of swaps to sort the array

Input Format

The first line contains an integer, n , the size of arr. The second line contains n space-separated integers arr[i]
image
image
image
image

About

HackerRank solution for minimum-swaps-2 in swift

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages