For a binary string s, keep shifting each '1' rightward until it either reaches the string's last position or is blocked by a different '1'. Afterward, all '0' characters must be on the left and all '1' characters on the right. Return the cumulative movement cost, defined as the total number of indices traversed by all moved '1' characters.
s = "10100" -> 5
This cost is exactly the count of (1, 0) pairs in which the '1' occurs earlier than the '0'; equivalently, it is the number of neighboring swaps required to move every '1' beyond every later '0'. Traverse the string from left to right while recording how many '1's have appeared. Whenever a '0' is found, add that running '1' total to the result. This avoids simulation and runs in O(n) time.
'1's across one '0', and the requested result is the operation total rather than the total distance moved. The same left-to-right counting idea applies (count prior ones and process each zero), but the returned quantity changes, so check whether the prompt asks for displacement cost or operation count.