This is the mock Quiz question. Can someone answer this?

Your friends – Raj & Suman – have moved into a new apartment. Their furniture is all in the wrong places in their new apartment. There is extremely limited room and hence they can only swap two pieces of furniture and they want to do this with as little effort as possible. The effort of swapping two pieces is the sum of their weights. The furniture has to be arranged such that the least heavy items are closest to the door.

Using your programming abilities, you need to advice them on the minimum effort required to put all the furniture in the correct places. You have to return minimal effort needed.

You are given the number of furniture items as a Non-zero positive integer and the weights of each item as an array. The first element of the array is the item closest to the door and the last element of the array is the farthest from the door. You have to swap the items in such a way that the least heavy item is closest to the door.

**Example 1:**

Input:

Number of furniture items: noOfFurnitures = 3

Weight of each furniture item: weight[] = {5,4,2}

Output:

The items can be put into their position in one step. Swap items 1 (weight 5) with item 3 (weight 2).

The resulting arrangement is (2,4,5) and the minimal effort, the output, is the sum of the weights: 5 + 2 = 7.

**Example 2:**

Input:

Number of furniture items: noOfFurnitures = 4

Weight of each furniture item: weight[] = {6,1,2,4}

Output:

Move 1: Swap item 2 (weight 1) & item 3 (weight 2). Resulting arrangement = (6,2,1,4). Effort = 1 + 2 = 3.

Move 2: Swap item 3 (weight 1) & item 4 (weight 4). Resulting arrangement = (6,2,4,1). Effort = 1 + 4 = 5.

Move 3: Swap item 1 (weight 6) & item 4 (weight 1). Resulting arrangement = (1,2,4,6). Effort = 6 + 1 = 7.

The total effort = 3 + 5 + 7 = 15. Hence the output is 15