Count Asterisks - Problem
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: Each '|' will belong to exactly one pair.
Input & Output
Example 1 — Basic Case
$
Input:
s = "l*e*et|code|*"
›
Output:
3
💡 Note:
The pairs are formed by 1st-2nd '|'. Outside the pair we have "l*e*et" (2 asterisks) and "*" (1 asterisk), totaling 3 asterisks.
Example 2 — Multiple Pairs
$
Input:
s = "iamprogrammer"
›
Output:
0
💡 Note:
No vertical bars and no asterisks, so the count is 0.
Example 3 — All Outside
$
Input:
s = "yo|uar|e**|awesome|"
›
Output:
2
💡 Note:
Pairs are 1st-2nd '|' and 3rd-4th '|'. Outside sections are "yo", "e**", and empty string after last '|'. Only "e**" contains asterisks (2 of them).
Constraints
- 1 ≤ s.length ≤ 1000
- s consists of lowercase English letters, '*', and '|'.
- s contains an even number of '|'.
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code