Minimum Swaps
Updated
Problem statement
You are given an array popularity containing the unique popularity ratings of n items.
The shopkeeper wants the items arranged from left to right in decreasing popularity.
- In one operation, the shopkeeper can swap any two items.
- Your task is to determine the minimum number of swaps needed to achieve the correct decreasing order.
Function
minimumSwaps(popularity: int[]) → intExamples
Example 1
popularity = [3, 4, 1, 2]return = 2Suppose there are n = 4 items, and popularity = [3, 4, 1, 2].
Output: 2
Explanation
- First swap: Switch items with ratings
3and4to get[4, 3, 1, 2]. - Second swap: Switch items with ratings
1and2to get[4, 3, 2, 1].
Constraints
1 ≤ n ≤ 2 × 10^51 ≤ popularity[i] ≤ n- Test Case Input Format
- The first line contains the integer
n. - The next
nlines contain an integer element ofpopularity[i].
- The first line contains the integer
More Akuna Capital Online Assessment questions
- Last Digit of the Ways to Split Traders Between Two OfficesOA · Seen Dec 2026
- Light Bulbs Left On After All Engineers FinishOA · Seen Dec 2026
- Delivery Management SystemOA · Seen Nov 2026
- Count Server ReplacementsOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
Similar questions at other companies
- API Rate Limit Violation DetectionTekion · OATekion interview questions
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Earliest Meeting Time for All EmployeesCapital One · OACapital One interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Largest Team Where Every Pair OverlapsWalmart · OAWalmart interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)