NeetCode #773LC-2938MediumGreedy
← Back to All Problems

#773 · #2938 · Separate Black and White Balls(区分黑球与白球)

📌 Problem Statement & Constraints

You are given a binary string s where 1 is a black ball and 0 is a white ball. In one operation you may swap two adjacent balls. Return the minimum number of swaps to group all black balls to the right. Constraints: 1 <= s.length <= 10^5.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!