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.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.