Please enter your email address or userHandle.
Given a string S contains 0's, 1's, and 2's, the task is to find the number of goals on the penalty.
Input: S = "1012012112110"
Explanation: There are 3 penalties,
of which he scores only 2.
Input: S = "111122"
Explanation: No goal on penalty
You don't need to read input or print anything. Your task is to complete the function penaltyScore() which takes a string S as input and returns the goals count on the penalty.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
1 <= |N| <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.