Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 1703. Minimum Adjacent Swaps for K Consecutive Ones
Given a binary array and an integer k, find the minimum number of adjacent swaps needed to make k ones consecutive by choosing which k ones to gather and minimizing the total distance they must move; this reduces to selecting k one-positions whose distances to their median are minimal and can be computed efficiently using the indices of ones (sliding window + prefix sums).
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.