
Consensus
A number of candidates are running for office. Each one has official positions on many issues, and these positions are given as a string, where the ith
character is a position on the ith
issue. A position can be Yes ('Y'
), No ('N'
), or undecided ('?'
).
A consensus position is one where all candidates either agree or are undecided. While candidates can be undecided, a consensus position cannot be (i.e. it can’t contain a '?'
position on any issue).
Given positions of the candidates, your job is to figure out in how many ways the candidates can reach consensus.
Example
-
For
candidate_positions = ["Y??", "??N"]
, the output should beConsensus(candidate_positions) = 2
.
There’re two consensus positions:"YYN"
and"YNN"
. -
For
candidate_positions = ["Y", "N"]
, the output should beConsensus(candidate_positions) = 0
.
It’s impossible to reach consensus in this example.
Input/Output
-
[execution time limit] 0.5 seconds
-
[input] array.string candidate_positions
Array of strings of the same length. Each string contain only characters
'Y'
,'N'
or'?'
.Constraints:
1 ≤ candidate_positions.length ≤ 16
,1 ≤ candidate_positions[i].length ≤ 16
. -
[output] integer
- The number of the position sets that all candidates can agree upon.
Post Comment