1130. Column Vote

Easy1.5 points estimatedMatrixCountingArray

A club votes on several motions at once. The ballot grid votes has one row per voter and one column per motion, and votes[r][c] is true when voter r says yes to motion c and false when they say no. Every voter votes on every motion.

Return an array with one boolean per column. Entry c must be true exactly when column c contains strictly more true values than false values; a tie, including a perfectly split column, produces false. The columns keep their original order.

Constraints: 1 <= rows, cols <= 50. Counting the yes votes of each column in a single sweep over the grid gives O(rows*cols) time and O(1) extra space beyond the output.

Example 1

Input:
votes = [[true,false,true],[true,true,false],[false,true,true]]
Output:
[true,true,true]
Explanation:

Each column has two yes votes out of three, so every motion passes.

Example 2

Input:
votes = [[true,false],[false,false],[true,false],[false,false]]
Output:
[false,false]
Explanation:

Column 0 is tied 2 to 2, which counts as false, and column 1 has no yes votes.

Constraints

1 ≤ rows, cols ≤ 50

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(rows*cols)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…