Ctrl K

Pegs With All Colors

Easy
A board has ten pegs numbered 0 to 9. Beads of three colors, red, green and blue, are threaded onto them. The string beads describes every bead with two characters: the first is its color ('R', 'G' or 'B') and the second is the peg number (a digit from '0' to '9'). For example, "G3R0" is a green bead on peg 3 and a red bead on peg 0. Return how many pegs hold beads of all three colors.
Example 1
beads='R5G5B5G2R2' → 1

Peg 5 has all three colors; peg 2 has only a green and a red bead. The answer is 1.

Example 2
beads='B1B1B1R1' → 0

Peg 1 holds four beads, but none of them is green, so the answer is 0.

Example 3
beads='G0B9R0B0R9G9' → 2

Both peg 0 and peg 9 carry a red, a green and a blue bead, so the answer is 2.

Constraints
  • beads.length = 2 · n, where 1 ≤ n ≤ 100
  • characters at even positions (0-indexed) are 'R', 'G' or 'B'
  • characters at odd positions are digits from '0' to '9'
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySame Letter Cipher EasySame Letters, Reshuffled EasySame When Flipped EasyShuffle Into a Palindrome Easy
loading Python…
Input
beads='R5G5B5G2R2'
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.