fork(1) download
  1. public class Solution {
  2.  
  3. public int minDeletionsToObtainStringInRightFormat(String p) {
  4.  
  5.  
  6. int cntA = 0, cntB = 0, delA = 0, delB = 0 ;
  7. char s[]= p.toCharArray();
  8. // for deleting B's from left to right
  9. for (int i = 0; i < p.length(); i++) {
  10. if (s[i] == 'B') cntB++;
  11. if (s[i] == 'A') {
  12. delB += cntB;
  13. cntB = 0;
  14. }
  15. }
  16.  
  17. // for deleting B's from right to left
  18. for (int i = p.length()-1; i >= 0; i--) {
  19. if (s[i] == 'A') cntA++;
  20. if (s[i] == 'B') {
  21. delA += cntA;
  22. cntA = 0;
  23. }
  24. }
  25.  
  26. return Math.min(delA,delB);
  27.  
  28. }
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
1 error
stdout
Standard output is empty