You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.

Return the number of '*' in s, excluding the '*' between each pair of '|'.

Note that each '|' will belong to exactly one pair.

&nbsp;
Example 1:

Input: s = "l|*e*et|c**o|*de|"
Output: 2
Explanation: The considered characters are underlined: "l|*e*et|c**o|*de|".
The characters between the first and second '|' are excluded from the answer.
Also, the characters between the third and fourth '|' are excluded from the answer.
There are 2 asterisks considered. Therefore, we return 2.

Example 2:

Input: s = "iamprogrammer"
Output: 0
Explanation: In this example, there are no asterisks in s. Therefore, we return 0.


Example 3:

Input: s = "yo|uar|e**|b|e***au|tifu|l"
Output: 5
Explanation: The considered characters are underlined: "yo|uar|e**|b|e***au|tifu|l". There are 5 asterisks considered. Therefore, we return 5.

&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 1000
	s consists of lowercase English letters, vertical bars '|', and asterisks '*'.
	s contains an even number of vertical bars '|'.


# Added on 2022-08-18 15:51:55.040392

var countAsterisks = function(s) {
    let green=true, count=0;
    for(let i=0; i<s.length; i++){
        if(green && s[i]=="*"){count++};
        if(s[i]=="|"){green=!green};
    }
    return count;
};
class Solution {
    public int countAsterisks(String s) {
        boolean insidePipe = false;
        int count = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == '|'){
                insidePipe = !insidePipe;
            }
            if(!insidePipe && s.charAt(i) == '*'){
                count++;
            }
        }
        return count;
    }
}
/*
1.) Maintain a counter to store the '|'
2.) After every even no. of '|' count the asteriks.
*/
class Solution {
public:
    int countAsterisks(string s) {

     int ans=0;

    // count of no. of '|'
        int cnt=0;

        for(int i=0;i<s.size() ;i++) {
         //if count is even then count the asteriks
              if(cnt%2==0) {
                  if(s[i]=='*') ans++;
              }
              if(s[i]=='|') cnt++;
        }
        return ans;
    }
};
var countAsterisks = function(s) {
    let green=true, count=0;
    for(let i=0; i<s.length; i++){
        if(green && s[i]=="*"){count++};
        if(s[i]=="|"){green=!green};
    }
    return count;
};
Count Asterisks