PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Akuna Capital

Find minimum swaps to sort array with duplicates

Last updated: Apr 15, 2026

Quick Overview

This question evaluates array manipulation and permutation-based reasoning for minimizing swap operations, including handling of duplicate values and performance considerations, within the Coding & Algorithms domain for a Data Scientist role.

  • hard
  • Akuna Capital
  • Coding & Algorithms
  • Data Scientist

Find minimum swaps to sort array with duplicates

Company: Akuna Capital

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Take-home Project

### Problem Given an integer array `nums` of length `n` that may contain duplicate values, you may perform swaps where you choose **any two indices** `i` and `j` and swap `nums[i]` and `nums[j]`. Return the **minimum number of swaps** required to reorder `nums` into **non-decreasing** order. ### Input - An integer array `nums`. ### Output - An integer: the minimum number of swaps needed to make `nums` sorted in non-decreasing order. ### Constraints - `1 <= n <= 2 * 10^5` - `-10^9 <= nums[i] <= 10^9` ### Notes - Because duplicates exist, there can be multiple valid sorted targets; your answer should be the minimum swaps over all valid ways to reach a sorted array. ### Examples 1. `nums = [2, 1, 2]` → sorted form is `[1, 2, 2]`, answer `1` (swap indices 0 and 1). 2. `nums = [1, 5, 1, 5]` → answer `1` (swap the two middle elements to get `[1,1,5,5]`).

Quick Answer: This question evaluates array manipulation and permutation-based reasoning for minimizing swap operations, including handling of duplicate values and performance considerations, within the Coding & Algorithms domain for a Data Scientist role.

Related Interview Questions

  • Compute Graph Spread and Portfolio Trades - Akuna Capital (medium)
  • Heapify an array into a max-heap - Akuna Capital (Medium)
  • Implement a ring buffer - Akuna Capital (Medium)
  • Compute max profit across dated stock quotes - Akuna Capital (Medium)
  • Break a palindrome to smallest non-palindrome - Akuna Capital (Medium)
Akuna Capital logo
Akuna Capital
Dec 27, 2025, 12:00 AM
Data Scientist
Take-home Project
Coding & Algorithms
7
0

Problem

Given an integer array nums of length n that may contain duplicate values, you may perform swaps where you choose any two indices i and j and swap nums[i] and nums[j].

Return the minimum number of swaps required to reorder nums into non-decreasing order.

Input

  • An integer array nums .

Output

  • An integer: the minimum number of swaps needed to make nums sorted in non-decreasing order.

Constraints

  • 1 <= n <= 2 * 10^5
  • -10^9 <= nums[i] <= 10^9

Notes

  • Because duplicates exist, there can be multiple valid sorted targets; your answer should be the minimum swaps over all valid ways to reach a sorted array.

Examples

  1. nums = [2, 1, 2] → sorted form is [1, 2, 2] , answer 1 (swap indices 0 and 1).
  2. nums = [1, 5, 1, 5] → answer 1 (swap the two middle elements to get [1,1,5,5] ).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Akuna Capital•More Data Scientist•Akuna Capital Data Scientist•Akuna Capital Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.