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

Method minFlips

MinNumberOfFlips.java:27–47  ·  view source on GitHub ↗
(string S)

Source from the content-addressed store, hash-verified

25
26// C++ Code
27int minFlips (string S)
28{
29 // your code here
30 int flips=0;
31 for(int i=0;i<S.length();i++)
32 {
33 if(i%2==0)
34 {
35 if(S[i]=='0') flips++;
36 }
37
38 else if(i%2!=0)
39 {
40 if(S[i]=='1') flips++;
41 }
42 }
43 if(flips<S.length()-flips)
44 return flips;
45 else
46 return S.length()-flips;
47}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected