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

Method countRev

CountTheReversals.java:3–21  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

1class Sol
2{
3 int countRev (String s)
4 {
5 // your code here
6 if(s.length()%2!=0) return -1;
7
8 int open=0,close=0,rev=0;
9
10 for(int i=0;i<s.length();i++)
11 {
12 if(s.charAt(i)=='{') open++;
13 else
14 {
15 if(open==0) close++;
16 else open--;
17 }
18 }
19 rev=(int)(Math.ceil(open/2.0) + Math.ceil(close/2.0));
20 return rev;
21 }
22}

Callers

nothing calls this directly

Calls 1

ceilMethod · 0.80

Tested by

no test coverage detected