A theatre's prop department has ten wheeled racks, numbered 0 through 9, standing in the wings. Throughout tech week, stagehands clip colored tags onto the racks to flag which props still need attention — every tag is red (R), green (G), or blue (B). You are given the full log of tag placements, in the order they happened, packed into one string: each placement is written as two characters, the tag's color followed by the digit of the rack it was clipped to. A rack that has, at any point, received at least one tag of each of the three colors is considered "fully flagged." Determine how many of the ten racks are fully flagged. (A rack may receive several tags of the same color; only the set of distinct colors it has ever seen matters, and the order of placements does not affect the final count.)
A single line containing a string s of even length 2n, formed by concatenating n placements. Each placement is two characters: an uppercase letter in {R, G, B} followed by a decimal digit 0-9.
Print a single integer: the number of racks (out of 0-9) that have received a tag of every one of the three colors.
s consists only of the characters described above, always arranged as color-then-digit pairs.Example 1
Input
B0B6G0R6R0R6G9
Expected
1
Explanation
Rack 0 receives B, then G, then R — all three colors, so it's fully flagged. Rack 6 receives B, R, R — only two distinct colors (B and R), so it is not flagged. Rack 9 receives only G. So exactly 1 rack is fully flagged.
Example 2
Input
B0R0G0R9R0B0G0
Expected
1
Explanation
Rack 0's placements are B, R, G, R, B, G in order — all three colors appear on rack 0, so it is flagged. Rack 9 only ever receives R. So the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →