DDSA Solutions

2980. Check if Bitwise OR Has Trailing Zeros

Time: O(n)
Space: O(1)

Problem Overview

Check if grid has unique values within each column and row.

Intuition

Check if grid has unique values within each column and row. Verify all grid entries are distinct in same row/col.

Algorithm

  1. 1For each row: check distinct. For each column: check distinct.

Common Pitfalls

  • Simple distinct check per row and per column. HashSet per row/column.
2980.cs
C#
// Approach: At least two even numbers (bit 0 = 0) must exist for their OR to have trailing zero.
// Time: O(n) Space: O(1)

public class Solution
{
    public bool HasTrailingZeros(int[] nums)
    {
        int cntEven = 0;

        foreach (int num in nums)
        {
            if (num % 2 == 0)
                cntEven++;
        }

        return cntEven >= 2;
    }
}
Was this solution helpful?

Related Problems