Minimum Row Deletions to Prevent a Target OR
Updated
Problem statement
You are given a non-empty rectangular binary matrix rows. Each row represents a non-negative integer in binary, with the leftmost column as the most significant bit. You are also given a positive integer target representable with the same number of bits.
The target is formable if the bitwise OR of one or more remaining rows equals target.
You may delete any rows. Return the minimum number of rows that must be deleted so that target is no longer formable. If the target is not formable initially, return 0.
Function
minimumRowsToDeleteForTargetOr(rows: int[][], target: int) → intExamples
Example 1
rows = [[0,0,0,0,1],[0,0,1,0,0],[0,1,0,1,0],[0,0,1,1,0],[0,0,1,1,1]]target = 14return = 1The target is 01110. It can be formed by the rows 00100 | 01010 or 01010 | 00110. Deleting the single row 01010 prevents every valid formation.
Example 2
rows = [[0,1],[1,0]]target = 3return = 1Both rows are needed to form 11. Deleting either one prevents the target.
Example 3
rows = [[0,0,1],[1,0,0]]target = 7return = 0No row contains the middle bit, so 111 is not formable even before any deletion.
Constraints
1 ≤ rows.length ≤ 100,0001 ≤ rows[i].length ≤ 30- All rows have the same length.
rows[i][j]is either0or1.1 ≤ target < 2^rows[i].length
More InMobi Onsite Interview questions
- Russian Doll EnvelopesONSITE INTERVIEW · Seen Jul 2026
- Minimum and Maximum with Optimal ComparisonsONSITE INTERVIEW · Seen Dec 2025
- Minimum Edges to Connect All ComponentsONSITE INTERVIEW · Seen Dec 2025
- Shortest Path Visiting All NodesONSITE INTERVIEW · Seen Sep 2025
- Maximum Sum of Non-Adjacent Tree NodesONSITE INTERVIEW · Seen Jan 2022
- Word SquaresONSITE INTERVIEW · Seen Jan 2022
- Maximum Length Pair ChainONSITE INTERVIEW · Seen Jul 2021
- Top View of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
- Maximum XOR Between Two ArraysONSITE INTERVIEW · Seen May 2021
- Trapping Rain WaterONSITE INTERVIEW · Seen May 2021
Similar questions at other companies
- Game of Life: In-Place Next GenerationGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximize K-Element AND with an Increment BudgetAmazon · OA
- Minimum Cost to Reach a Target WeightChubb · OAChubb interview questions
- Maximum XOR Elimination ScoreRippling · OARippling interview questions
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Server SelectionPoint72 · OAPoint72 interview questions
- Minimum Servers for an Exact LoadJP Morgan Chase · OAJP Morgan Chase interview questions
- Make Pixel Columns Strictly IncreasingMicrosoft · OAMicrosoft interview questions
- Server SelectionAirbnb · OAAirbnb interview questions