MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / minimumSteps

Method minimumSteps

SeparateBlackAndWhiteBalls.java:2–13  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

1class Solution {
2 public long minimumSteps(String s) {
3 int n=s.length();
4 int last=0;
5 long swapCount=0;
6 for(int cur=0;cur<n;cur++){
7 if(s.charAt(cur) == '0'){
8 swapCount+=(cur-last); //imag swapping
9 last++;
10 }
11 }
12 return swapCount;
13 }
14}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected